Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

=+c. If you were to learn that a bottle of Gatorade

Answered: 1 week ago