Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago