For this assignment, you will implement a simple spell checker that processes a text file, reading every word from the file and displaying those that are misspelled (i.e., those that are not found in the dictionary). You are given the Dictionary class and a skeleton of the SpellChecker class. To guide you through completing the implementation of this class, the assignment is broken into four distinct stages. It is strongly recommended that you complete the class in stages and test your code thoroughly before moving on to the next stage.
Complete the definition of the SpellChecker
constructor. The constructor should
initialize the Dictionary
field so that it reads in and stores the words from the specified
file. The dictionary file dictionary.txt,
which contains an astonishing 117,662 English words,
has been provided for your use. Download a copy of this file and store it
in your BlueJ project folder in order to make it accessible.
Once you have your constructor working, complete the definition of the checkWord
method. This method takes a word as input, and returns true if that word is stored in the dictionary,
else false. The comparison should ignore capitalization and any non-letters in the word. For example,
if "banana" is stored in the dictionary, then the checkWord
method should return true when
called with "banana", "Banana", and even "BANANA!!!".
Next, implement the checkFile
method, which reads all of the words from a file and displays any misspelled words. The method has
a single parameter, the name of the text file to be spell-checked. The method should open that
file, read each word from the file, and display any word that does not appear in the loaded dictionary.
As before, the comparison should ignore capitalization and any non-letters in the word.
To test your method, you should construct several small files of words using a text editor, and
save those files in the BlueJ project folder.
As currently described, the checkFile
method may report numerous duplicates.
That is, if a person misspells the same word 10 times in a document, the method would report that
misspelled word 10 times. For the final stage, you are to modify your checkFile
method
so that there are no duplicates reported. In order to do this, your checkFile
method
should have a local variable of type Dictionary
that can store the misspelled words.
Instead of
immediately displaying a misspelled word when it is encountered, the method should add that word to the
new Dictionary
using the addWordNoDupes
method, which will assure that
only one copy of that word is stored. When done processing the entire file, the method should
then display all of the misspelled words in the Dictionary
.
SpellChecker
class via BlueLine.