CSCI 161: Pig Latin
Overview
Write a program that translates an English word into a Pig Latin word. Input ONE, and ONLY one, word from the user, and then output its translation to Pig Latin.
The rules for converting a word to Pig Latin follow.
- The general form for converting a word is to remove the first letter. Then append to the end of the word a hyphen, followed by the first letter that was removed, followed by “ay”. For example, “robot” becomes “obot-ray” and “Hello” becomes “ello-Hay”.
- If the word begins with a vowel (an element of “aeiouAEIOU”) simply append “-way”. For example, “example” becomes “example-way” and “All” becomes “All-way”.
- If the word begins with “th” (or “Th”, “tH”, or “TH”), remove the prefix and append “-thay” (or “-Thay”, “-tHay”, or “-THay”) to the word. For example, “this” becomes “is-thay” and “The” becomes “e-Thay”.
Use at least the REQUIRED METHODS listed below, with the exact same SPELLING for method names and parameters.
Input Specification
Input ONE English word as a string. If multiple words are entered ignore any beyond the first.
Use PRECISELY the format below with the EXACT same SPACING and SPELLING.
Please enter a word ==> <user input>
Output Specification
Output an introductory message, a prompt for the English word, and a translation for the inputted word.
Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output below assumes the user entered “Hunger”.
This program will convert an English word into Pig Latin.
Please enter a word ==> Hunger
"Hunger"
in Pig Latin is
"unger-Hay"
Required Methods
// Prompt and read a word to translate
public static String readWord (Scanner console)
// Convert a word to Pig Latin and return it
public static String convertWord (String englishWord)
// Return true if "c" is a vowel, false otherwise.
// Handle both lowercase and uppercase letters.
public static boolean isVowel (char c)
// Print result of translation
public static void printResult (String englishWord, String pigLatinWord)
Hints
BEFORE you start coding, think about which methods each method will call. Which methods should “main” call? Create a diagram which shows the calling relationships.
There are many useful String methods listed HERE.
You may find startsWith
and charAt
helpful.
Style
Use good programming style:
- Write comments
- Choose mnemonic, meaningful variable names (e.g. balance, interestRate)
- Indent consistently (Ctrl-Shift-F will format your code)
- Remember the comment block at the top of your program
Submission
Please name your program PigLatin.java
Submit the Java source code file on Autolab under the “Pig Latin” assignment.
Grading
- 20 points will be awarded for having a well-formatted, well-documented source code file. This includes your name, date, description, and comments throughout the program. This also includes other style requirements, such as method naming conventions. NOTE: The autograder will not display these points.
- 10 points will be awarded for having proper input from a user.
- 60 points will be awarded for having methods that do what they are expected to do with correct parameters and return types
- 10 points will be awarded for having proper output that matches EXACTLY
- NOTE: if your program does not compile/run, the highest score you will earn will be a 20/100