package cse1030; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.HashSet; public class Dictionary { private HashSet words; public Dictionary(String filename) throws IOException { HashSet wordsFromFile = new HashSet(); BufferedReader r = null; try { r = new BufferedReader(new FileReader(filename)); boolean done = false; do { String word = r.readLine(); if (word != null) { wordsFromFile.add(word.trim()); } else { done = true; } } while (!done); this.words = wordsFromFile; } catch (IOException ex) { throw ex; } finally { if (r != null) { r.close(); } } } public boolean lookUp(String word) { return this.words.contains(word); } }