Question: This exercise requires that you write a Java program that uses classes in the Java Class Library to create a hash table with your own
This exercise requires that you write a Java program that uses classes in the Java Class Library to create a hash table with your own hashing function, search that hash table, and then print the results.
You will write a Java program that has at least two classes: the primary class containing main and a second class, HashObject, defining objects that will be hashed into your hash table. main will be the entry point/driver of your program. The HashObject class should have two attributes, one should be Integer and the other should be String. You may isolate the functionality of your solution by creating additional classes and or methods if you wish.
Your program should declare a HashMap object from the Java Class Library HashMap class. The initial capacity should be 100, and the initial load factor should be .75. The keys should be Integers and the values should be HashObjects.
Your program should input two data files. Both files contain records with two fields. The first field is an Integer. The second field is a String. You are to read the first file, Lab4InputFile1, and use each Integer/String pair to create a new HashObject object. You should generate a hash key from the data in the object and add it to the hash table. It is your responsibility to ensure the fewest number of hash collisions, so you might have to experiment with your hashing function to that end. Your ultimate objective should be to devise a perfect hashing function.
The second file contains search objects. You are to read the second file, Lab4InputFile2, and use each Integer/String pair to create new HashObject objects. Using the hashing function you devised above, you are then to generate a hash key from the data in the object and determine if the search object is in the hash table using the functionality of HashMap.
You should print two reports. The first should include a count of the number of objects from Lab4InputFile1 and a list of the key and value data for each item in the hash table. (This should also demonstrate the quality of your hash function.) The second report should include the results of the searches. It should include the generated hash key, the Integer and String fields of each Lab4InputFile2 object, and whether it was found or not. Acquiring the data for these reports will likely require you to iterate in some form through the entries of the hash table. Review of the material of the Java HashMap Class Presentation we covered in class might be a good starting point for you.
Submit your NetBeans project file as a .zip file through Canvas as detailed in the Lab Submission Guidelines document. Email submissions will not be accepted. When executing your program In NetBeans, the working directory is the directory of your project. To facilitate us evaluating your work, add the data file to your project directory. Do not change the file name. All internal references to the file in your program should be the file name only. Do not include the full path.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
