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
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, below but i cannot find my error. i will appreciate if you can find for me
import java.util.Scanner; public class pp1 { private static class PigLatin{ private static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter the phase word):"); String sentence= input.nextLine(); sentence=sentence.replaceAll(" + ", " "); System.out.print("The phase "); System.out.println("\"" + sentence + "\"" +" "); Scanner word = new Scanner (sentence); System.out.println("Would have the following appearance in Pig Latin:"); System.out.print("\""); while (word.hasNext()){ String pigLatin = word.next(); System.out.print(conertPigLatinPhrase(pigLatin)); } } private static String conertPigLatinPhrase(String inputWord) { int length = inputWord.length (); if (inputWord.charAt(length - 1) == '.' || inputWord.charAt(length - 1) == '!' || inputWord.charAt(length - 1) == '?') { char ch = inputWord.charAt(0); String rest = inputWord.substring(1, length - 1); return (rest + "-" + ch + "ay" + inputWord.charAt(length - 1) + "\""); } else if ((inputWord.charAt (0) == 't'|| inputWord.charAt (0) == 'T') && inputWord.charAt (0) == 'h'){ return (convertTH(inputWord));} else if (isVowel (inputWord.charAt (0))){ return (inputWord + "-ay");} else{ char ch = inputWord.charAt(0); String rest = inputWord.substring(1); return (rest + "-" + ch + "ay"); } } private static String convertTH(String inputWord) { char t = tWord.charAt(0); char h = tWord.CharAt(1); String rest = tWord.substring(2); return (rest + "-" + t + h + "ay");} private static boolean convertPigLatinPhrase (String englishPharse){ String word = convertPigLatinWord(englishPhrase); return (word + " "); private static boolean isVowel(char char c) { if (c =='a' || c== 'A' ){ return (true);} else if (c == 'e' || c =='E'){ return (true);} else if (c == 'i' || c =='I'){ return (true);} else if (c == 'o' || c =='O'){ return (true);} else if (c == 'u' || c == 'U'); return (true);} else { return (false); } } }
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