Help: The Hashtable Class


Help is available for each task, or you can go straight to the solution source code.

Task 1

Add statements to import the new classes to be used.
Click on the Company class in the Magelang/JavaBasics package from the Workspace window. Add "import java.util.Hashtable" and "import java.util.Enumeration" before the class Company {...} declaration (in the bottom pane).

Task 2

Replace the array with a Hashtable in the Company class. Use Employee as both the key and value.
Change the type of the employees variable to Hashtable. Remove the array brackets. Initialize the Hashtable to have 10 entries. Modify the addEmployee method to use the Hashtable method put.

Task 3

Rewrite the findEmployee method to use the Hashtable for the search.
Use the Hashtable method get.

Task 4

Rewrite the findEmployeeNamed method to enumerate through the Hashtable to do the search.
Use the Enumeration class to iterate through the Hashtable, as shown in the course notes.

Task 5

Rewrite the toString method of the Company class to use the Hashtable.
Enumerate through the Hashtable as in the task above.

Task 6

Run the program via the HashTest class.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.