Question
1 Project Requirements. Based on HashTable.java and LinkedList2.java given below. Refine the program to make it more useful. Your program should read in a text
1 Project Requirements.
Based on HashTable.java and LinkedList2.java given below. 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 Run your program make sure it is working correctly (1) Project9.java (2) HashTable.java (3) LinkedList2.java
______________________________________________________________________ public class HashTable { private LinkedList2[] hashArray; private static int SIZE = 10; public HashTable() { //(1) create a linked list array hashArray //with size of SIZE(10) hashArray = new LinkedList2[SIZE]; for (int i=0; i< SIZE; i++) //hashArray = ?; hashArray[i] =new LinkedList2(); //(2) initialized the hashArray with 10 empty linked lists } private int computeHash(String s) { int hash = 0; for (int i=0; i < s.length(); i++) { hash+=s.charAt(i); } //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 int hash = computeHash(s); LinkedList2 list = hashArray[hash]; if (!list.contains(s)) { hashArray[hash].addToStart(s); }
} } ________________________________________________________________ __________________________________________________________________
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
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