Java - Pig Latin Translator

From WLCS

Objective:

  • You will create a program that translates English to Pig Latin

Translation Rules:

  1. If a word has no letters, don't translate it.
  2. Separate each word into two parts. The first part is called the prefix and extends from the beginning of the word up to, but not including, the first vowel. (The letter y will be considered a vowel.) The rest of the word is called the stem.
  3. The Pig Latin text is formed by reversing the order of the prefix and stem and adding the letters ay to the end. For example, sandwich is composed of andwich + s + ay and would translate to andwichsay.
  4. If the word contains no consonants, let the prefix be empty and the word be the stem. The word ending should be yay instead of merely ay. For example, I would be Iyay.

Directions (bad style):

  1. Prompt the user to enter a word
  2. Check for the length of the string and handle the rules above appropriately
  3. Determine the index/location of the first vowel (Hint: use a String method/function)
  4. If there is a vowel, then save the prefix (the substring before the vowel) and the stem (the substring starting at the vowel through the end of the string)
  5. Print out the Pig Latin version of the word (following the rules above)