Question: Write the definition of a class named Dictionary whose state is the name of a file. The Dictionary class offers one constructor and one method,

Write the definition of a class named Dictionary whose state is the name of a file. The Dictionary class offers one constructor and one method, found. The constructor gets the name of a file and initializes the state accordingly. The method, found, recieves one argument, a String, and opens up the file indicated by the instance variable. It then reads all the words in the file, converting them to lower case, and returns true if and only if the word argument to found, when converted to lower case, matches one of the Strings read from the file.

Then, write a program named SpellCheck1 that creates a Dictionary object (based on a file named "Dictionary") and then reads a file named paper line by line, keeping count of the line numbers as it does. With each line, the programexamines every word in the line (hint: use a Scanner based on the String holding the line). For each word in the line, the program invokes the found method in the Dictionary object. If found returns true (i.e. the word is found in the object), then the word is spelled correctly and no action is taken. Otherwise, the program displays the line number and the word to standard output (thus indicating the spelling error and where it occurred). The format of the output line is this: first "Line " literally. Then the line number displayed in a field of FOUR positions. Then, a colon and a space... and finally the misspelled word itself. For example:

Line 47: neccesary

Note: in this program, every lookup of a word (i.e. every invocation of found) must involve opening the dictionary file, searching it, and then (reminder!) closing it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!