Instruction
Learning objectives:
Use hash tables, a common data structure, to implement a programming problem
Implement a spelling checker by using a hash table. Start by reading the starter code.
Use the following steps:
Your code should import this code from the textbook:
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/SeparateChainingHashST.java.html (Links to an external site.) and use it as a library. Do not change this code. (The starter code already implements this.)
In the initDictionary() method, write code that reads a file of words and creates a hash table of correctly spelled words. The file of words is provided for you in the GitHub repository.
Write code in main() that repeatedly prompts the user to type a word and checks each word for spelling mistakes.
If the word is spelled correctly (found in your hash table), it should print "no mistakes found".
If the word is not found, it should list all words that are obtainable by applying any of the following rules exactly once:
Add one character to the beginning
Add one character to the end
Remove one character from the beginning
Remove one character from the end
Exchange two adjacent characters
There are two ways to implement part 3:
Given an input word inputWord, loop over all words in the hash table (using the keys() method) and for each word dictionaryWord, check if you can go from inputWord to dictionaryWord using one of the five transformations.
Given a word inputWord, generate a list stringList of all possible strings you can make by applying one of the five rules. Then, for each string s in stringList, look up s in the dictionary.
Pick which way you think is better for this problem (in terms of number of comparisons). Implement it, and explain why you think it's better.
Examples (add your own too):
input word output
algorithm no mistakes found!
cate cater, cat
og bog, cog, dog, fog, hog, jog, log, mog, nog, pog, sog, tog, go
Starter code:
In Eclipse:
Right-click on the "Lab3" icon in the left sidebar.
If using eclipse with git, you may need to first right-click on the "cis27" folder and then select Team, then Pull, before you can see the "Lab3" icon.
Select "Build Path" from the pop-up menu, then select "Add Libraries..." from the second menu that pops up.
Make sure "JRE System Library" is selected (highlighted).
Click Next.
Click Finish.
Right-click on the "Part2" folder underneath the "Lab3" icon.
In the menu that pops up, select "Build Path", then select "Use as source folder" from the second menu that pops up.
To run the code, right-click on the "SpellChecker.java" icon in the sidebar and select "Run As", then "Java application" from the second menu that pops up. You can also go to the Run menu > "Run As" > "Java application".
The code just prints out all the words in the dictionary. Change it so that it implements a spell checker as per the assignment.