//////////////////////////////////// // Your name. // Your lab section. // Today's date. //////////////////////////////////// import java.awt.*; import java.awt.event.*; public class PigLatin extends java.applet.Applet implements ActionListener { TextField inputF; TextArea tArea; Button process; String result; public void init () { result = ""; inputF = new TextField(60); tArea = new TextArea(3, 60); process = new Button("Process"); process.addActionListener(this); add(inputF); add(process); add(tArea); } public boolean isVowel(char c) { if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') { return true; } else { return false; } } // findFirstVowel returns the index of the first occurrence // of a vowel in a word public int findFirstVowel(String word) { // declare and intiialize counter variable int i; i = 0; // loop through the characters in a word while (i < word.length()) { if (isVowel(word.charAt(i))) return i; i = i + 1; } return (-1); } // Subroutine ConvertToPigLatin (from Prelab) public String ConvertToPigLatin(String s) { String result = ""; // Case 1: the word begins with a vowel // This case has been done for you already // Take string s and add "way" to the end of it if (findFirstVowel(s) == 0 ) { result = (s + "way"); } // Case 2: the word doesn't begin with a vowel but has one in it else if (/* value of findFirstValue(s) for above to be true*/) { // # FILL IN - set result to what? // # Hint: use substrings } // Case 3: the word doesn't have any vowels else { // # FILL IN - set result to what? } return result; } public void actionPerformed(ActionEvent event) { int index; String s = //Fill in value for initial value of "s"; while ((index = s.indexOf(" ")) != -1)//what does this loop do? //what conditions need to be true to continue executing the loop? { // ** Add your code here! ** // } // When does this loop stop? What else has to still be done? // ** Add your code for the last word here! ** // tArea.append("\n"); //Goes to the next line } }