Commit 3510724a authored by marc.sheppard's avatar marc.sheppard

Add new file

parent e1efcdfc
import java.util.ArrayList;
import java.util.List;
/**
* Main program code
*
* @author Marc.
* Created 17 Nov 2019.
*/
public class Translator {
static int languages = 3;
private List<String[]> dictionary = new ArrayList<String[]>();
//constructor
public Translator() {
//add words/phrases to dictionary
addWord("hello","bonjour","hallo");
addWord("goodbye","adieu","auf wiedersehen");
addWord("thank you","merci","dankeschön");
addWord("my","mon","mein");
addWord("the","le","das");
addWord("be","être","sein");
addWord("to","à","zu");
addWord("of","de","von");
addWord("and","et","und");
addWord("a","un","ein");
addWord("in","dans","im");
addWord("that","ce","das");
addWord("have","avoir","haben");
addWord("i","je","ich");
addWord("it","il","es");
addWord("for","pour","zum");
addWord("not","ne pas","nicht");
addWord("on","sur","auf");
addWord("with","avec","mit");
addWord("he","il","er");
addWord("she","elle","sie");
addWord("you","toi","du");
addWord("time","temps","zeit");
addWord("person","la personne","person");
addWord("year","l' année","jahr");
addWord("way","façon","weg");
addWord("day","journée","tag");
addWord("thing","chose","sache");
addWord("world","monde","welt");
addWord("life","la vie","leben");
addWord("place","endroit","ort");
}
//returns translated word if it is in the dictionary else returns an empty string (note: case sensitive)
//input and and output languages (0 = English, 1 = French, 2 = German)
public String translate(String word,int input_language,int output_language) {
int dic_size = this.dictionary.size();
//search for matching word by iterating though each word in the dictionary
for(int index=0;index<dic_size;index++) {
//check if current word in inputed language matches inputed word and if so return translated word
if(this.dictionary.get(index)[input_language].equals(word)) { return this.dictionary.get(index)[output_language]; }
}
//if no matching word is found
return "";
}
//add word/phrase to dictionary (note: case sensitive)
private void addWord(String english,String french,String german) {
int index = this.dictionary.size();
this.dictionary.add(new String[languages]);
this.dictionary.get(index)[0] = english;
this.dictionary.get(index)[1] = french;
this.dictionary.get(index)[2] = german;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment