Hey guys, I need a little help on PigLatin translator. This is "driver" class I'm given that I cannot change
import java.util.*;
public class PigDriver{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String t = " ";
Piglatin p = new Piglatin();
while(t.length() > 0){
t = scan.nextLine();
t = t.toLowerCase();
p.pigConvert(t);
}
p.pigReport();
}
}
And this is my body to my other Piglatin class except when I test my code, it works but only sometimes. Letters like "b, g, z" sometimes dont work and the "aeiou" doesnt always work either. Can anyone help?
Here's my code that can be edited/changed
import java.util.*;
public class Piglatin{
public void pigConvert(String t){
String result = "";
StringTokenizer word = new StringTokenizer(t," ?!.,");
while(word.hasMoreTokens()){
result += convertWord(word.nextToken());
result += " ";
}
System.out.println(result);
}
//this method translates a sentence into piglatin
private String convertWord(String word){
String result = "";
for (int i = 0; i < word.length(); i++){
if(startVowel(word.charAt(i))){
result = word + "ay";
}
else{
result = word.substring(1) + word.charAt(0) + "ay";
}
}
return result;
}
//this method converts a word into piglatin
private boolean startVowel(char x){
return x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u';
}
//this method checks to see if the word begins with a vowel
public void pigReport(){
System.out.println();
}
}
//this method prints out the input in pig latin
EDIT: Here are some example outputs
Input: "how is this string of words working?"
Output: "owhay siay histay tringsay foay ordsway orkingway"
Input: a bear can do everything from growling happy inside jokingly to knocking little men now
output: aay earbay ancay doay verythingeay romfay rowlinggay appyhay insideay okinglyjay toay nockingkay littleay enmay ownay