Question
1. This application will create a hash table (MyChainHashTable) with chaining. See section 18.2 in the text. The main hash table (the buckets) will be an array. Each of the buckets will be a linked list (BucketList) of all the elements with the same hash. (IOW, the hash table will be an array of linked lists.)
2. The Vs in the hash table mapping will be Employee19 objects, and the Ks will be the employee IDs.
3. The HashedEmployees class has the main method. It will use an object of the
MyChainHashTable class to store Employee19 objects.
a. The main method in HashedEmployees will just call the no-arg constructor, which will have the main UI loop.
b. The constructor should create the hash table using the following declaration: Map<String, Employee> table = new MyChainHashTable<>(); (Although the declaration specifies Employee as the type for the values,
Employee19 objects will actually be added.)
c. The UI should allow user input like the Sample Run.
4. The Employee19 class extends the chapter 16 Employee class. It has:
a. A no-arg constructor that does nothing.
b. A 3-arg constructor that passes all its args to the super class constructor.

c. A new toString that produces a shorter String than the super class. (This is the reason for the new class.)
5. The MyChainHashTable will implement the Map interface. Only two of those methods (put (K, V) and remove(K, V)) will be implemented. The other Map methods can be left as stubs.
a. The constructor should initialize an array of buckets, which will be BucketList class objects. Since there are 10 hash values (see 5d below) there will be 10 buckets. Use a constant for the 10.
b. The put method adds the specified value to the hash table, using the key provided. Determine which bucket to use based on the hash function, passing it the key. Maps can only store a single V for a given K. The put method returns the replaced V if the K was already present, or null otherwise.
c. The remove method removes the specified value from the hash table, using the key provided. Returns whatever the BucketList remove method returns. Hint: this remove method only knows about K (ID) and V (Employee). The UI only has the ID available, but must create an Employee to call this function. Only the ID field is important.
d. The hash function is based on the old dial phones, where the letters illustrated in the Sample Run were associated with the digits. Q and Z were not on the original phones. They were placed in various places over the years, but we will put them on ‘1’.
e. The toString method will return the multi-line String shown in the Sample Run below. Q and Z are not shown in the toString, but Employees with IDs beginning with Q and Z will show up on the ‘1’ line. It calls the BucketList toString to print the {...} parts.
6. The BucketList class is a thin wrapper around a LinkedList object. It will have the methods specified, which use a MyLinkedList object to store the data.
a. add method. Since Maps only hold one value for a given key, the BucketList add method will check to see if a matching object (based on the equals method in the Employee class) is already in the linked list (use indexOf) and remove it with the remove(index) method, then add the new object in the same place using the 2-arg add method. If the object isn’t already in the list, add it to the end with the 1-arg add method.
b. The remove method will just return whatever the remove method in the
MyLinkedList class returns.
c. The toString method produces { … } shown in the Sample Run. It uses the Es toString to print the part within the { }s
7. The MyLinkedList class and the Employee class is supplied. Import them using the existing package name. Do not change the classes.


Sample Run
User input in bold red.

Available commands are:
p firstname lastname ID (to put) r ID (to remove)
q (to quit)
Enter command: p George Washington gw001
1 {}

2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {}
6 MNO {}
7 PRS {}
8 TUV {}
9 WXY {}
0 {}

Enter command: p John Adams ja002
1 {}

2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {Adams, John (ja002)}
6 MNO {}
7 PRS {}
8 TUV {}
9 WXY {}
0 {}

Enter command: p Thomas Jefferson tj003
1 {}

2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {Adams, John (ja002)}
6 MNO {}
7 PRS {}
8 TUV {Jefferson, Thomas (tj003)}
9 WXY {}
0 {}

Enter command: p James Madison jm004

1 {}
2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {Adams, John (ja002); Madison, James (jm004)}
6 MNO {}
7 PRS {}
8 TUV {Jefferson, Thomas (tj003)}
9 WXY {}
0 {}

Enter command: x unrecognized command: x Available commands are:
p firstname lastname ID (to put) r ID (to remove)
q (to quit) 1 {}
2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {Adams, John (ja002); Madison, James (jm004)}
6 MNO {}
7 PRS {}
8 TUV {Jefferson, Thomas (tj003)}
9 WXY {} 0 {}

Enter command: r ja002
1 {}

2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}
5 JKL {Madison, James (jm004)}
6 MNO {}
7 PRS {}
8 TUV {Jefferson, Thomas (tj003)}
9 WXY {}
0 {}

Enter command: r ja002
ja002 not found. 1 {}
2 ABC {}
3 DEF {}
4 GHI {Washington, George (gw001)}

5 JKL {Madison, James (jm004)}
6 MNO {}
7 PRS {}
8 TUV {Jefferson, Thomas (tj003)}
9 WXY {}
0 {}

Enter command: q
So, it has come to this.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

package edu.brcc.maxfieldj.ch16lab1a;

/**
* basic Employee to use with Set and Map collections
* https://docs.google.com/document/d/1THPPB3TNycEtTR80fwr1u-DpVF2Q729jIdjZycx9src/edit?usp=sharing


*/
public class Employee {
    private String firstName; // first name of the employee
    private String lastName;   // last name of the employee
    private String ID;         // employee ID, unique key

    /**
    * basic no-arg constructor
    */
    public Employee() {
    }

    /**
    * constructor to set all attributes
    * @param firstName of the employee
    * @param lastName of the employee
    * @param ID       of the employee
    */
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$60.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 641 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,803+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,660+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,421+ sessions)
2 hours avg response

Similar Homework Solutions