Java Reference
In-Depth Information
the test program at the end of
Section 16.3
. Call the
debug
method after
all additions and removals and verify that
Figure 6
accurately represents
the state of the hash table.
Exercise P16.4. Write a program that keeps a map in which both keys and
values are stringsȌthe names of students and their course grades. Prompt
the user of the program to add or remove students, to modify grades, or to
print all grades. The printout should be sorted by name and formatted like
this:
Carl: B+
Joe: C
Sarah: A
Exercise P16.5. Reimplement Exercise P16.4 so that the keys of the map
are objects of class
Student
. A student should have a first name, a last
name, and a unique integer ID. For grade changes and removals, lookup
should be by ID. The printout should be sorted by last name. If two
students have the same last name, then use the first name as tie breaker.
If the first names are also identical, then use the integer ID. Hint: Use
two maps.
760
761
Exercise P16.6. Supply compatible
hashCode
and
equals
methods to
the
Student
class described in Exercise P16.5. Test the hash code by
adding
Student
objects to a hash set.
Exercise P16.7. Supply compatible
hashCode
and
equals
methods to
the
BankAccount
class of
Chapter 7
. Test the
hashCode
method by
printing out hash codes and by adding
BankAccount
objects to a hash set.
Exercise P16.8. Design an
IntTree
class that stores only integers, not
objects. Support the same methods as the
BinarySearchTree
class in
the topic.
Exercise P16.9. Design a data structure
IntSet
that can hold a set of
integers. Hide the private implementation: a binary search tree of
Integer
objects. Provide the following methods:
ȗ A constructor to make an empty set