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

What is wrong with my method? Directions: Write your code in the file PigLatin.j

ID: 3759294 • Letter: W

Question

What is wrong with my method?

Directions:

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.

My Answer:

public class PigLatin {
   public static String translate(String original){

       System.out.println("Enter a word.");
       original = IO.readString();
      
       String originalFixed = original.toLowerCase();
       char firstLetter = originalFixed.charAt(0);
      
       String translated = "";
      
       if (firstLetter == 'a' || firstLetter == 'e' || firstLetter == 'i' || firstLetter == 'o' || firstLetter == 'u')
           translated = original + "way";
       else
           translated = original.substring(1) + firstLetter + "ay";
          
       return translated;
   }
}

Explanation / Answer

public class PigLatin
{
public static void main(String[] args)
{
translate("word");
}

public static String translate (String original)
{
char firstChar;
String pig;
System.out.println("Enter a word.");
String word = IO.readString();
word = word.toLowerCase();

firstChar = word.charAt(0);
if(firstChar == 'a' || firstChar == 'e' || firstChar == 'i' || firstChar == 'o' ||
firstChar == 'u'){
pig = word + "way";
}
else{
pig = word.substring(1) + word.charAt(0) + "ay";
}
System.out.println(pig);
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