Difference between revisions of "Java - Pig Latin Translator"

From WLCS
(Created page with "'''Objective:''' * You will create a program that translates English to Pig Latin '''Translation Rules:''' # If a word has no letters, don't translate it. # Separate each word i...")
 
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
# If a word has no letters, don't translate it.
 
# If a word has no letters, don't translate it.
 
# 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.
 
# 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.
# 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 s + andwich + ay + . and would translate to andwichsay.
+
# 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.
 
# 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.
 
# 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):'''
 
'''Directions (bad style):'''
*# Prompt the user to enter a word
+
# Prompt the user to enter a word
*# Check for the length of the string and handle the rules above appropriately
+
# Check for the length of the string and handle the rules above appropriately
*# Determine the index/location of the first vowel (Hint: use a String method/function)
+
# Determine the index/location of the first vowel (Hint: use a String method/function)
*# 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)
+
# 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)
*# Print out the Pig Latin version of the word (following the rules above)
+
# Print out the Pig Latin version of the word (following the rules above)

Latest revision as of 08:26, 15 October 2015

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)