CIS300 Fall 2000: Assignment 7

15 points; due Monday, November 19, at 3:00pm

A hash table is yet another example of a ``dictionary'' data structure.

Assignment

Modify the word-counting program that you built for Assignment 6 by removing the SpellingTree package and replacing it by a HashTable package that implements a hash table that will save words and their counts. See the Assignment 6 handout for the requirements of the word-counting program.

Implementation

Almost all of your work will be dedicated to writing these two classes:
package HashTable
public class HashTable
{ private Word[] table;   // array that holds words and their counts

  ... // methods that add a word into the table and print the table's contents
}


package HashTable;
public class Word
{ private String the_word; // the word acts as its own ``key'' 
  private int the_words_count;

  ... // methods that increment the_words_count  and return the value of
      // the_word  and  the_words_count
}
You should construct the the hash table as an array of prime-numbered size (e.g., 101 elements). Also, you must use the polynomial coding technique for computing the hash function; remember to use an appropriate base, e.g., 37 or 41.

There is only one annoyance to writing this program: When the program prints the final listing of words and their counts, it must do so in alphabetical order. You should not assume that the words are inserted into the hash table in alphabetical order (indeed, they will not be inserted alphabetically), so you should use a standard sorting technique (e.g., selection or insertion sort) to format and print the final listing. (A hint: Make class HashTable hold a private variable, int total_count, that remembers the count of Word objects saved in the table. When it is time to print the contents of the hash table, construct an array, new Word[total_count], copy the contents of the hash table into the array, and sort the contents of the array. Then print the sorted array's contents to the output file.)

Submission

Verify that your program is started by the command,
java WordCounter.Start
as for Assignment 6. Create a folder, Assign7, that holds package WordCounter and package HashTable. Run javadoc on the HashTable package.

Create the jar file, Assign7.jar, and submit at http://www.cis.ksu.edu/classes/300/Assign/submit.html. This concludes your programming efforts for CIS300.