Question
Write the definition of a class named Dictionary whose state is an array of words (Strings). The Dictionary classoffers one constructor and one method, found
Write the definition of a class named Dictionary whose state is an array of words (Strings). The Dictionary classoffers one constructor and one method, found. The constructor gets the name of a file and reads all the words in the file twice. The first time to count how many words there are (in order to know how big to make the array), the second time converting them to lower case and using them to initialize the array. The method, found, recieves one argument, a String, and returns true if and only if the word argument, when converted to lower case, can be found in the array of the Dictionary object.
Then, write a program named SpellCheck3 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: the file named "Dictionary" is read twice, at the beginning of the program, by the constructor of the one Dictionary object being created. The first time it is read is to find out how many words there are in the dictionary file, so as to know how big to make the array.
Submit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started