Question: Project Requirements. Based on HashTable.java and LinkedList2.java you practiced during the class. Refine the program to make it more useful. Your program should read in
Project Requirements.
Based on HashTable.java and LinkedList2.java you practiced during the class. Refine the program to make it more useful. Your program should read in a text file, parse each word, see if it is in the hash table, and, if not, output the line number and word of the potentially misspelled word. Discard any punctuation in the original text file. Use the words.txt file as the basis for the hash table dictionary. The file contains 87,314 words in the English language. Test your spell-checker on a short text document.
2 Hints.
Create a hash table dictionary.
Load all the words in words.txt file into the dictionary.
Each word should be lowercase before save to dictionary.
Remove all the punctuation for each word before save to dictionary.
You can have a method removePunct()
You can have a method checkWord()
3 Sample Results: Sample File for checkme.txt: The quick brown fox jumpz over the lazy dogs. Were there some typoos in there somewhere? There should be one pur line. Sample Output:
1 Checking file jumpz may be misspelled on line 1
typoos may be misspelled on line 2 in may be misspelled on line 2
be may be misspelled on line 3
pur may be misspelled on line 3
4 Submission Run your program make sure it is working correctly. Please submit your source files to blackboard:
(1) Project9.java
(2) HashTable.java
(3) LinkedList2.java
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(2) HashTable.java
public class HashTable { private LinkedList2[] hashArray; private static final int SIZE = 10; public HashTable() { //(1) create a linked list array hashArray //with size of SIZE(10) //hashArray = ?; //(2) initialized the hashArray with 10 empty linked lists } private int computeHash(String s) { int hash = 0; //calculate hash return hash%SIZE; } public boolean containsString(String target) { int hash = computeHash(target); LinkedList2 list = hashArray[hash]; if(list.contains(target)) return true; return false; } public void put(String s) { //(1) Get hash values //(2) Get the list corresponding to the hash value // of the hashArray //(3) add the String s to the start of the list } } ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3) LinkedList2.java
public class LinkedList2 { private class Node { private String item; private Node link; public Node() { link = null; item = null; } public Node(String newItem, Node linkValue) { item = newItem; link = linkValue; } } private Node head; public LinkedList2() { head = null; } public void addToStart(String itemName) { head = new Node(itemName,head); //System.out.println(head.getLink()); } public boolean deleteHeadNode() { if(head != null) { head = head.link; return true; } else return false; } public int size() { int count = 0; Node position = head; while(position != null) { count++; position = position.link; } return count; } public boolean contains(String item) { return (find(item) != null); } private Node find(String target) { Node position = head; String itemAtPosition; while(position != null) { itemAtPosition = position.item; if(itemAtPosition.equals(target)) return position; position = position.link; } return null; } public void outputList() { Node position = head; while(position != null) { System.out.println(position.item + " "); position = position.link; } } public boolean isEmpty() { return (head == null); } public void clear() { head = null; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
