I have to design a program that converts English into Pig Latin. I am having difficulty in converting all words contained within the input provided by the user to Pig Latin. With my current code, I achieve an output of:
Input: This is not working
Output: histay is not workingay
While my desired output is:
Input: This is not working.
Output: Histay ishay otnay orkingway
What am I doing wrong? I'm just looking for a push in the right direction.
public class piglatin {
// A program designed to convert English words in to Pig Latin
public static void main(String[] args) {
char a, e, i, o, u, A, E, I, O, U, b;
String alphabet = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
Scanner word = new Scanner (System.in);
System.out.println("Please enter a word: ");
String incoming = word.nextLine();
System.out.println("Input: " + incoming);
String newincoming = incoming.substring(1);
String newerincoming = incoming.substring(0,1);
a = alphabet.charAt(0);
e = alphabet.charAt(8);
i = alphabet.charAt(16);
o = alphabet.charAt(28);
u = alphabet.charAt(40);
A = alphabet.charAt(1);
E = alphabet.charAt(9);
I = alphabet.charAt(17);
O = alphabet.charAt(29);
U = alphabet.charAt(41);
b = incoming.charAt(0);
if ((b == a) || (b == e) || (b == i) || (b == o) || (b == u) || (b == A) || (b == E) || (b == I) || (b == O) || (b == U)) {
System.out.println("Output: " + incoming + "hay");
} else {
System.out.println("Output: " + newincoming + newerincoming + "ay");
}
}
}