Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program to demonstrate using hash tables. Doing more file processin

ID: 3812980 • Letter: W

Question

Write a Java program to demonstrate using hash tables. Doing more file processing, you will read in a dictionary file, dictionary.txt, and use its contents to spell check a file, checkme, that is provided on the command line. This project is not an in-depth, comprehensive program in the nature of root words, tense, plurals or endings. Rather many words of varying form (plurals, possessives) will be provided in the dictionary file. You will need to create two Java files: Project.java and StringHash.java. Given: • A file of 125,000+ dictionary words. • A file to be spell checked provided on the command line. • A hash multiplier of 31 and a bucket value of 4093 passed to the constructor. Create a StringHash class. Here is some code to get you started: public class StringHash { Node[] buckets; private int BUCKETS; private int MULT; public StringHash (int buckets, int mult) { /* Complete the constructor */ } public int hashValue(String s) { int h; int x, l = s.length(); h = 0; for ( x =0; x < l; x++ ) h = h * MULT + s.charAt(x); if ( h < 0 ) h = -h; return (h % BUCKETS); } You will need to create a constructor and a Node inner-class similar to the Linked-List topic. Create the following methods in a newly created StringHash class: public boolean hasWord(String word); public void add(String word); Now create a Project class for testing the StringHash class. This class will also have your main() method. Use the following in the Project class: public static String removeNonLetDig(String s) { int b = 0, e = s.length()-1; // Trim from the beginning while (b <= e && !Character.isLetterOrDigit(s.charAt(b))) b++; // Trim from the end while (e >= b && !Character.isLetterOrDigit(s.charAt(e))) e--; if (b <= e) return s.substring(b,e + 1); else return null; } Your input file will be given on the command line. The dictionary file should be hard coded as dictionary.txt. Read the dictionary file into the hash table using the add() method. Use the hashValue() method to find the appropriate bucket for a given word. Once a bucket is found add the word to the list for that bucket. An ordered list is not needed here as a linear search of the bucket list should not be too expensive due to the hash. *NOTE*: You must either lower case or upper case the words as they are entered into the hash table. Lookups will be consistent later as hasWord() must do the same when you request a word lookup. After the hash table is populated with the dictionary words, open the file to be spell checked and read words from the file one at a time. Check the word against the hash table using hasWord(). Display to standard output those words that are not spelled correctly or do not appear in the hash table. Your output should look like: specialized yacc.c bison.simple C LALR(1 lalr1.cc C bison-patches@gnu.org glr.c Generalized LR C LALR(1 C 2002 and/or 2 59 330 02111-1307

Explanation / Answer

import java.io.*;

class wordbook
Boolean flag = false;
String sub = new String();
String strf = new String();

try
metal = new FileReader("dictionaryTXT.txt");
BufferedReader pellet = new BufferedReader(fr);
  
while((strf = pellet.readLine()) != null)
  
}
}


/*
Output

dictionaryTXT

blame:to knock.
compete:to try and do higher than one's fellow in work.
daring:courage.
errant:wandering.
futile:worthless.
goodwill:kindly feeling.


E:&gt;java wordbook
daring
daring:courage.

E:&gt;java wordbook
Vidyadhar
Word not found

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote