Question
Below is the question: Write an interactive program that reads lines of input from the user and converts each line into Pig Latin. Pig Latin
Below is the question: Write an interactive program that reads lines of input from the user and converts each line into Pig Latin. Pig Latin is English with the initial consonant sound moved to the end of each word, followed by ay. Words that begin with vowels simply an ay appended. terminate the program when the user types a blank line.
For example, the phrase
The deepest shade of mushroom blue
Would have the following appearance in Pig Latin:
e-Thay eepest-day ade-shay of-ay ushroom-may ue-blay. I already made a code, and below is my code:
public class Translate{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Please type in a sentence: "); while(input.hasNext()){ System.out.print("Please type in a sentence: "); String newSentence = input.nextLine(); pigLatin(newSentence); }
} public static void pigLatin(String sentence){ Scanner lineScan = new Scanner(sentence); String temp = ""; while(lineScan.hasNext()){ String aWord = lineScan.next(); int counter = 0; String newWord = ""; while(!(aWord.charAt(counter) == 'a' || aWord.charAt(counter) == 'e' || aWord.charAt(counter) == 'i' || aWord.charAt(counter) == 'o' || aWord.charAt(counter) == 'u' || aWord.charAt(counter) == 'A' || aWord.charAt(counter) == 'E' || aWord.charAt(counter) == 'I' || aWord.charAt(counter) == 'O' || aWord.charAt(counter) == 'U')){ newWord += aWord.charAt(counter); counter++; } newWord += "ay"; aWord = aWord.substring(counter); aWord += "-" + newWord; temp += aWord + " "; } System.out.println(temp); } } But now I am stuck on setting up the test condition to make true the pigLatin will run as long as the input is not blank. Where I did wrong in my code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started