Question: Here is my code. But in myProgrammingLab there are a few unexpected results. import java.util.Scanner; public class PigLatin { public static String convertWord(final String englishWord)

Here is my code. But in myProgrammingLab there are a few unexpected results.

import java.util.Scanner;

public class PigLatin {

public static String convertWord(final String englishWord) {

for (int i = 0; i

if (isVowel(englishWord.charAt(i)))

return (englishWord.substring(i) + "-" + englishWord.substring(0, i) + "ay");

}

return englishWord + "-ay";

}

public static boolean isVowel(final char c) {

return "aeiouAEIOU".contains(String.valueOf(c));

}

public static void main(final String[] args) {

final Scanner console = new Scanner(System.in);

String phrase;

do {

System.out.print("Enter a sentence to translate:");

phrase = console.nextLine();

if (phrase.trim().length() > 0) {

String pigLatinPhrase = "";

final String words[] = phrase.trim().split(" ");

for (int i = 0; i

pigLatinPhrase += convertWord(words[i]) + " ";

}

System.out.println(""+pigLatinPhrase);

}

} while (phrase.trim().length() > 0);

console.close();

}

}

Expected Result: Enter a sentence to translate: It was a dark andstormy-nighte It-ay-as-way a-ay-ark-day-and-ay ormy-stay.ight-nay. Enter a sentence to translate: Ships at a

Expected Result: Enter a sentence to translate: It was a dark and stormy-nighte It-ay-as-way a-ay-ark-day-and-ay ormy-stay.ight-nay. Enter a sentence to translate: Ships at a distance have every man's wish.on-boarde ips-Shay-at-ay-a-ay-istance-day-ave-hay-every-ay-an's-may-ish-way-on-ay-oard-bay. In-ay--myay-ounger-yay-and-ay-ore-may-ulnerable-vay Enter a sentence to translate:In-my-younger and more vulnerable years my father game me some advice ears-yay--myay ather-fay-ame-gay-e-may-ome-say-advice-ay. Enter a sentence to translate: In the late summer of that year we lived-in-a-house-in-a-village In-ay e-thay-ate-lay.ummer-say-of-ay-at-thay-ear-yay e-way-ived-lay-in-ay-a-ay-ouse-hay-in-ay-a-ay-illage-vay. Enter a sentence to translate: Your Code's Actual Result: Enter a sentence to translate: It was a dark and stormy .night It-ay-as-way-a-ay-ark-day-and-ay-ormy-stay.ight-nay. Enter a sentence to translate:Ships at a distance have every man's wish on-board ips-Shay-at-ay-a-ay-istance-day-ave-hay-every-ay-an's-may-ish-way-on-ay-oard-bay.. Enter a sentence to translate:In-my-younger and more vulnerable years my father game me some advice In-ay-my-ay-ounger-yay and-ay-ore-may-ulnerable-vay ears-yay-my-ay-ather-fay ame-gay-e-may-ome-say-advice-ay. Enter a sentence to translate:In the late summer of that year we lived in a house in a village In-ay-e-thay-ate-lay-ummer-say-of-ay-at-thay-ear-yay e-way-ived-lay-in-ay-a-ay-ouse-hay-in-ay-a-ay-illage-vay. Enter a sentence to translate:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!