Saturday, February 4, 2012

How do I code a pig latin translator in java?

My assignment:


Create a program that converts an English Sentence into a Pig Latin Sentence. If a word begins with a consonant then remove the first letter, put the first letter to the end with "ay" added to the end. Example: john = "ohn jay".


If a word begins with vowel, then keep the word as is. Don't worry about punctuation of the output.


______________________________________鈥?br>

I am in basic basic basic java. So you need to help me as much as possible. We are at if-then statements and loops.








Help me start the code and guide me through to help me learn this. I don't want you to do the work for me.


______________________________________鈥?br>




public class WordConverter


{


public static void main(String[] args)


{


String englishSentence, pigLatinSentence;


String pigLatinEnding;


pigLatinEnding = "ay";














}





}

















}|||you will need to separate vowels and consonants - compare first letter against vowel array





private static final String[] vowels = { "a", "e", "i", "o", "u", "y" };





next split words


String[] words = sentence.split(" ");





then loop words and detect which ones need to be changed


for(int i = 0; i %26lt; words.length; i++)


{


String firstLetter = word[i].substring(0, 1);


boolean change = true;


int j = 0;


while(j %26lt; vowels.length)


{


if(firstLetter.toLowerCase().equals(vo鈥?change = false;


j++;


}


if(change) ??? change the word


else ??? leave the word


}





I hope this points you in the right direction

No comments:

Post a Comment