Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This exercise requires that you write a Java program that uses classes in the Java Class Library to create and use a hash table. You

This exercise requires that you write a Java program that uses classes in the Java Class Library to create and use a hash table.

You are to write a Java program that has at least three functions: main, hashFunction, and hashTablePrint. main will be the entry point/driver, hashFunction will be called to generate the hash key for a value you wish to add to a hash table, and hashTablePrint will be called to print a formatted report of the key/value entries in the hash table.

Your program should declare a HashMap object from the Java Class Library HashMap class. You may use the default initial capacity and load factor.

Your program should input a data file which contains text strings. You should not modify the file itself. You will be able to view and become familiar with the file, but you should still write a general program. You should not write your program to work with this file, specifically. Your program should work properly for files containing any number of strings.

The file, Lab4InputFile, will contain alphanumeric strings of varying lengths. You should input the strings from the file and insert them into your HashMap. You should call your hashFunction method to generate the hash key for each string you insert into your HashMap. The hash key for each string should be the first character from the string.

When you have inserted all the strings from the file into your HashMap, call should your hashTablePrint method to print the contents of the hashMap. Then delete the first string read from the file from the HashMap and call hashTablePrint again to print the altered HashMap.

You should not write hashTablePrint using toString() to print the hash table. You should iterate over the HashMap to access the individual entries. You should declare an iterator over the HashMap to do this. You should cast each entry you obtain with your iterator as a Map.Entry and then access the key and value using the Map.Entry getKey() and getValue() methods.

You should print a clearly labeled, formatted report of your results.

InputFile.txt

red green blue orange black yellow lilac purple tan

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Why is price flooring not a part of the market mechanism?

Answered: 1 week ago