Answer:
Hi there Sandrathompson5661!
Using Java as the language for implementation, the PigLatin translation program can simply be coded as shown below. The program uses the Scanner module in java utils package to prompt the user for input of word(s) and splits the input with any of the matching delimiters. The rule to swap the first character and append it to the end with an “ay” for a normal word, or the appending of “yay” for a vowel word, is then applied. The result is printed on the screen before the program exits.
Step-by-step explanation:
import java.util.Scanner;
public class PigLatin {
public static void main(String[] args) {
char[] delimiterChars = { ' ', ',', '.', ':', ';', '\t' };
String[] words_array;
Scanner words = new Scanner(System.in);
System.out.println("Please enter a word (for multiple words use any of the following delimiters {' ', ',', '.', ':', ';', '\t' }): ");
String input_words = words.nextLine();
words_array = input_words.split("[,\\s\\-:.;' '\\\t]");
System.out.println("PigLatin translation: ");
for (int i=0; i<words_array.length; i++) {
System.out.println(makePigLatin(words_array[i]));
}
}
public static String makePigLatin(String word) {
String vowels = "aeiou";
if (vowels.indexOf(Character.toLowerCase(word.charAt(0))) != -1) {
word = word + "yay";
}
else {
word = word.substring(1, word.length()) + word.charAt(0) + "ay";
}
return word;
}
}