Hello. As a personal project, I am trying to create a "Java Argot" translator. However I am having some issues.
The purpose of the program is to translate a sentece into the following "Secret Languages": "Pig Latin", "Leet" and "Morse Code". I have only done the "Pig Latin" translator however, everytime I try to activate case one in the "switch case" I get the error message "Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0".
The program shows that the line of code that is sending this message is these two lines: "PigLatin_Translator.main(word);
" in the "Translator Menu" and "if(word[count].charAt(0) == 'a' || word[count].charAt(0) == 'e' || word[count].charAt(0) == 'i' || word[count].charAt(0) == 'o' || word[count].charAt(0) == 'u')
" in the "PigLatin_Translator". I don't know why the system has an "Index Out of Bounds" error when the program does not give the user a chance to type in a string of code (if it allowed the user to type in a string of code then it would have an index). Please Help. Thank You.
Main Menu for Translator Code (some parts of code are removed since no translator is available yet for the other switch cases
Scanner scan = new Scanner (System.in);
System.out.println("****Welcome to the \"Argot \" translator. A translator that translates some common and un-common forms of \"Secret Language\"**** ");
System.out.println("|Look below at the menu to naviage to which translator you would like to use...");
System.out.println("|Translator Name | Transator Number|");
System.out.println("|The \"PigLatin\" Translator | Press \"1\" on your keyboard to activate|");
System.out.println("|\"The \"Morse Code\" Translator | Press \"2\" on your keyboard to activate [Comming Soon]|");
System.out.println("|\"The \"Leet\" Translator | Press \"3\" on your keyboard to activate [Comming Soon]|");
int option = scan.nextInt();
//Switch case that navigates though translator options
switch(option){
case 1:
//Asks user to type in a sentence for the translator
System.out.print("Type in a word so it can be translated into \"Pig Latin \": ");
String wordTyped = scan.nextLine();
//Sends the letter to all Lowercase
String wordLowercae = wordTyped.toLowerCase();
//Separates string of words into different words
String[] word = wordLowercae.split(" ");
PigLatin_Translator.main(word);
System.out.println();
//Tells the user the "PigLatin Translation
System.out.print("Here is the \"Pig Latin \" translation: ");
Pig_Latin Translator Code
public static void main(String[] word) {
Scanner scan = new Scanner (System.in);
//Loop that controls the separated words
for (int count = 0; count < word.length; count++ ) {
//Pig Latin Rule for "Vowels" (excluding "Y")
if(word[count].charAt(0) == 'a' || word[count].charAt(0) == 'e' || word[count].charAt(0) == 'i'
|| word[count].charAt(0) == 'o' || word[count].charAt(0) == 'u') {
String newWord = word[count] + "-yay";
System.out.print(" " + newWord);
}