I need to write a class called PigLatin. The main method of this class uses a Scanner to ask for an input sentence in English, then prints out its translation in Pig Latin. Assume that the input sentence is in all lower-case, and does not contain any punctuation or extra spacing. Here is a sample run of the program:
sentence to translate
the quick brown fox jumped over the lazy dog //input by user
ethay uickqay ownbray oxfay umpedjay overway ethay azylay ogday
I conceptualized the code I would need to write beforehand to help. But the problem is I don't know how to actually write it :/ I figure I need to write at least 3 big methods (with maybe some smaller ones to help).
The first method will tokenize the input. It'll take in a String and return a String array, so that each word in the input can be analyzed and changed. I was thinking to make two arrays, one that has way more entries that I will need, and then copy that array to another one, but only the non-null (space) elements. So now I'll have a String array with all the words separated.
This second method will detect the consonant's prefix. The input and output will both be Strings I think. Maybe chars? The output will return the prefix to be sent to the end of the word. So if I call the method with the word "quick" it will return "q". If I call it with "one" it should return "" (because it's a vowel) and if I call it for "brown" it should return "br".
This last method will actually translate the word. It will take a String as input, the word in English to be translated, and the method will return the word in pig latin as a string. This method will have to call upon the 2nd method to get the prefixes to translate.
Then I need to write a bit of code to print out the sentence.
Hopefully my concepts are accurate and I didn't forget anything huge I need.
Aucun commentaire:
Enregistrer un commentaire