Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write your code in the file PigLatin.java. Your code should go into a method wit

ID: 3681040 • Letter: W

Question

Write your code in the file PigLatin.java. Your code should go into a method with the following signature. You may write your own main method to test your code. The graders will ignore your main method: public static String translate (String original){} "Pig Latin" is a fake language used as a children's game. A word in English is "translated" into Pig Latin using the following rules: If the English word begins with a consonant, move the consonant to the end of the word and add "ay". The letter Y should be considered a consonant. If the English word begins with a vowel (A, E, I, O, or U), simply add "way" to the end of the word. (This is a simplified dialect of Pig Latin, of course.) Write your method so that it returns the pig latin translated original string. You may assume that the input does not contain digits, punctuation, or spaces. The input may be in any combination of uppercase or lowercase. The case of your output does not matter.

Explanation / Answer

java program:


import java.io.*;
import java.util.Scanner;
public class PigLatinTest {
public static void main(String []args)throws IOException{
String Str="";
Scanner scan=new Scanner(System.in);
while(!Str.equalsIgnoreCase("Quit")){
System.out.print(" Enter a String to translate into Pig Latin(if you enter Quit it will stop):");
Str=scan.next();
System.out.println("original String="+Str+" Pig Latin String="+translate(Str));
}
}
public static String translate (String original){
char ch=original.charAt(0);
String newString;
if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
newString=original+"way";
else
newString=original.substring(1)+ch+"ay";
return newString;
}
}

output:

Enter a String to translate into Pig Latin(if you enter Quit it will stop):DurgaRao
original String=DurgaRao Pig Latin String=urgaRaoDay

Enter a String to translate into Pig Latin(if you enter Quit it will stop):Original
original String=Original Pig Latin String=Originalway

Enter a String to translate into Pig Latin(if you enter Quit it will stop):Quit
original String=Quit Pig Latin String=uitQay
BUILD SUCCESSFUL (total time: 1 minute 17 seconds)