Due: Tuesday, November 21, 2017 @ 10:00AM
Write a program that translates an English phrase into a Pig Latin phrase. Input a phrase from the user and translate it to pig latin. You can assume the phrase will be on a single line.
Use at least the REQUIRED METHODS listed below, with the exact same SPELLING for method names and parameters.
The input will be an English phrase, with NO terminal punctuation. Read the phrase as a SINGLE STRING using the nextLine
method.
Use PRECISELY the format below with the EXACT same SPACING and SPELLING.
Please enter a phrase ==> <user input>
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 "Humpty Dumpty sat on the wall".
This program will convert an English phrase into Pig Latin.
Please enter a phrase ==> Humpty Dumpty sat on the wall
"Humpty Dumpty sat on the wall"
in Pig Latin is
"umpty-Hay umpty-Day at-say on-way e-thay all-way"
// Prompt and read a phrase to translate
public static String readPhrase (Scanner console)
// Convert a phrase to Pig Latin and return it
public static String convertPhrase (String englishPhrase)
// 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)
You already wrote a method to convert a single word (convertWord
). Apply it to each word in the phrase, forming the translated phrase by concatenating the translated words. If you did not get convertWord
working on the first lab assignment, you need to get it working now.
Class Scanner
can process a String
(instead of System.in
) consisting of multiple words, and break it into words that are separated by whitespace (tabs, spaces, and newline characters). You know other ways to break a line into words, so you do NOT have to use this technique.
Correctly handle whitespace before and after words.
Use good programming style:
Ctrl+Shift+F
will format your code)Please name your program PigLatin.java
Submit the Java source code file on Autolab under the "Lab 9" assignment.