CS1C Information About Programming and Style Rules Assignments Project
Quadratic Probing with a find()
Make sure you have read and understand the Modules Information About Programming Assignments and Style Rules for Assignments before submitting this assignment.
Adding find() to Our Hash Table
This week you will implement find() using the ideas presented in the modules. As you have done recently you will realize the generic by deriving from the base class FHhashQP.
The Spec
Derive the class generic FHhashQPwFind from FHhashQP. It will take a second type parameter KeyType as you saw in the modules. The syntax for this is:
public class FHhashQPwFind
Add the following public method:
E find(KeyType key) returns the found object, or throws a java.util.NoSuchElementException
Add the following protected (or private) methods:
int myHashKey( KeyType key) a trivial modification to myHash() which uses the key rather than the object, to hash.
int findPosKey( KeyType key ) a trivial modification to findPos() which uses the key rather than the object, to get a position.
Client Requirements
Create two wrapper classes for EBookEntry: EBookCompInt and EBookCompString. Each one contains a singleEBookEntry object and overrides the toString(), compareTo(), equals() and hashCode() methods. It also must declare that it implements the Comparable< "¦ > interface for the appropriate basic type, Integer or String. This is done for you in the modules for Employees you can use that as a template.
In main() instantiate an FHhashQPwFind hash table based on one of these two wrapper classes.
Test this on EBookEntry data by reading the data from the file, then wrapping each book and adding the wrapped object to the hash table (no array needed).
Generate 25 random integers (scaled to the number of EBookEntries) to use as special indices. Then display the 25 from the original array (provided by the EBookEntryReader class) followed by 25 find() calls, which report success (show the found book) or failure (show a simple “not found” String).
Test find() on two or three keys that you know are not in the hash table.
Do everything twice, once using the int eTextNum as a key field, and a second time using a string key field, like title or creator. The accessors and mutators of EBookEntry will help you with this. You can provide one main()with one set of key choices left in and the other commented out, rather than two mains.
Here is an example of what I mean (the various occurrences of “”¦” stand for omitted code that is not important to the example):
// ———– wrapper classes ————-class EBookCompInt implements Comparable