I wont write this for you but ill give you some hints on how to write this class:
1. Before anything else, its obvious that this class will need a string to hold all of the translated data.
public class Piglatin {
private String outputPiglatin;
//Method bodies etc...
}
2. pigConvert() needs to take a string as a parameter, and since the result isn't stored in a variable the methods type can be void. Your method heading for the pigConvert() should look like this :
public void pigConvert(String inputString) {
//Your code here
}
3. Inside pigConvert you will need to write a few things:
a. Split inputString into seperate words like so:
String words[] = inputString.split(" ");
b. a for loop which goes through all the words in "words", looking for vowels and placing ay at the end of the words with vowels. The words without vowels will just need to have the letter put at the end of the original word without its first letter and then 'ay' is added:
this.outputPiglatin = "";
for(int i=0; i
{
switch(words[i].charAt(0)) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
words[i] = words[i] + "ay";
this.outputPiglatin = this.outputPiglatin + words[i] + " ";
break;
default:
words[i] = words[i].substring(1) + words[i].charAt(0) + "ay";
this.outputPiglatin = this.outputPiglatin + words[i] + " ";
break;
}
}
4. Now for pigReport(). Since this takes no parameters and doesnt have its result stored in any variable in the pigDriver class, it can also be void. This method only will have to print out the string to the user:
public void pigReport() {
System.out.println(outputPiglatin);
}
That's a rough code outline and it'll probably take you about 20 minutes to write this.