I am making a translator that takes english and translates it into a made up language called Talhamr. To do this I take user input and make it into an array. Then I test it against a word bank array that contains english words with the corresponding Talhamr word next to it. If the english word works I want to replace it with the corresponding Talhamr word. Can any one help me code this? bellow is the code I have so far.
Main class:
import java.util.Scanner;
public class Translator {
public static String userInput = "";
public static String[] wordBank = {"a/an","Ai","about","circa" /*...*/};
public static void main(String[] args) {
/**
* getting input
*/
Scanner scanner = new Scanner(System.in);
System.out.print("Write something to be translated into ancient language: ");
/**
* formatting input
*/
userInput.toLowerCase();
userInput = scanner.nextLine();
String[] wordArray = userInput.split(" ");
/**
* Creating a, and preforming english to talhammir, translation
*/
EtoT e2t = new EtoT();
e2t.translateToTalhamr(wordArray, wordBank);
System.out.println(wordArray[0]);
/**
* This is how I formatted the word bank. After I went to quizlet and changed all the spaces between rows and columns to "-"
* String makeNice = ...;
* System.out.println("\""+ makeNice.replace("-", "\",\""));
*/
}//end of main method
}//end of Translator class
Second class containing translation method:
public class EtoT {
/**
* establishing word bank to loop through and translate
*/
public String[] wordBank = {"a/an","Ai","about","circa" /*...*/};
public EtoT() {
}
public String translateToTalhamr(String[] wordArray, String[] wordBank) {
for (int i=0; i < wordArray.length; i++) {
System.out.print("'");
for (int j = 0; j < wordBank.length; j++) {
System.out.print(".");
if (wordBank[j] == wordArray[i]) {
System.out.print(",");
wordArray[i] = wordBank[j + 1];
} else {
wordArray[i] = wordArray[i] + "!";
}
}//end of inner word bank
}//end of outer for loop
System.out.println("\n" + wordArray.toString());
return wordArray.toString();
}//end of translateToTalhamr
public static void main(String[] args) {
}//end of main method
}//end of EtoT