In: Computer Science
how would I be able to implement a hash table into a spell checker program while using a StringNode class in java that checks for spelling mistakes?
import java.util.ArrayList;
import java.util.Scanner;
public class SpellCheck {
private Dictionary dict;
final static String filePath = "d:/desktop/words.txt";
final static char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
SpellCheck() {
dict = new Dictionary();
dict.build(filePath);
}
void run() {
Scanner scan = new Scanner(System.in);
boolean done = false;
String input;
if (input.equals("")) {
break;
}
if (dict.contains(input)) {
System.out.println("\n" + input + " is spelled correctly");
} else {
System.out.print("is not spelled correctly, ");
System.out.println(printSuggestions(input));
}
}
}
String printSuggestions(String input) {
StringBuilder sb = new StringBuilder();
ArrayList<String> print = makeSuggestions(input);
if (print.size() == 0) {
return "and I have no idea what word you could mean.\n";
}
sb.append("perhaps you meant:\n");
for (String s : print) {
sb.append("\n -" + s);
}
return sb.toString();
}