I didn't have java installed so it took a minute extra.
Code
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Scanner;
import java.nio.file.Files;
import java.nio.charset.Charset;
import java.nio.file.Paths;
public class HelloWorld {
public static void main(String []args){
try {
Scanner input = new Scanner(System.in);
HashMap<String, String> dictionary = new HashMap<String, String>();
List<String> temp = Files.readAllLines(Paths.get("C:/temp", "dict.txt"),Charset.defaultCharset());
for(String s : temp) {
dictionary.put(s.split("\\s")[0], s.split("\\s")[1]);
}
System.out.println("Welcome to the English to Spanish dictionary.");
while (true) {
System.out.println("Enter an english word or q to quit: ");
String word = input.nextLine();
if(dictionary.containsKey(word)) {
System.out.printf("The english word '%s' translates to the spanish '%s'\n", word, dictionary.get(word) );
} else if (word.equals("q")) {
break;
} else {
System.out.println("That word was not in the dictionary.");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Edit forgot the friggin main lmao.
Edit 2: Not sure if you HAD to read the thing from a file. It does now
This post was edited by waraholic on Nov 2 2016 03:40pm