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

Problem 1 Write your code in the file PigLatin.java. Your code should go into a

ID: 675347 • Letter: P

Question

Problem 1

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

Answer :

import java.util.*;

class pigLatin {
public static void main(String[] args) {

   System.out.print("Enter any word: ");
Scanner kb = new Scanner(System.in);
String original;
original = kb.next();

  
  
String pigs=translate(original);
System.out.println("The pigLatin word is: " +pigs);
}
public static String translate (String word)
{
     
   char first;
   String pig;
     
   word = word.toLowerCase();
   //System.out.println(word);
  
   first = word.charAt(0);
   if (first == 'a' || first == 'e' || first == 'i' ||
    first == 'o' || first == 'u') // for vowel
    pig = word + "way";
   else
    pig = word.substring(1) + word.charAt(0) + "ay";
  
   return pig;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote