I have code where one method takes user input and converts a single word into pig latin. But, I need to convert a whole phrase into pig latin and I do not know how to convert the whole nextline() statement into pig latin as opposed to just one word.
I have thought of using a for loop and other things I just do not understand how I would break the user input into single words
import java.util.*;
public class PigLatin {
public static void main(String[] args) {
System.out.println(" This Program creates pig latin out of the user inputted word");
System.out.println();
Scanner console = new Scanner(System.in);
System.out.println("Type a word in:");
String userWord = console.nextLine();
convertWord( userWord);
}
public static void convertWord(String word) {
word = word.toLowerCase();
char first = word.charAt(0);
//String middle = word.substring(2);
String partWord = word.substring(1,word.length());
if( first == 'a' || first == 'e' ||first == 'i' ||first == 'o' ||first == 'u' ) {
System.out.println(word + "-way");
} else {
//char last = word.charAt(word.length() - 1);
System.out.println(partWord + "-" + word.charAt(0) + "ay");
}
}
}
I expect to input any phrase and if it will put the equivilent but each word is in pig latin. If the word starts with a vowel it will append the word plus -way. or else it will append the word followed by the first letter and then it will output (ay). I need all the words in the phrase to do this .