Java Reference
In-Depth Information
Exercise P9.3. A person has a name and a height in centimeters. Use the
implementation of the
DataSet
class in
Section 9.4
to process a
collection of
Person
objects. Display the average height and the name of
the tallest person.
Exercise P9.4. Modify the implementation of the
DataSet
class in
Section 9.1
(the one processing
Measurable
objects) to also compute the
minimum data element.
432
433
Exercise P9.5. Modify the implementation of the
DataSet
class in
Section 9.4
(the one using a
Measurer
object) to also compute the
minimum data element.
Exercise P9.6. Using a different
Measurer
object, process a set of
Rectangle
objects to find the rectangle with the largest perimeter.
Exercise P9.7. Enhance the
DataSet
class so that it can either be used
with a
Measurer
object or for processing
Measurable
objects. Hint:
Supply a default constructor that implements a
Measurer
that
processes
Measurable
objects.
Exercise P9.8. Define an interface
Filter
as follows:
public interface Filter
{
boolean accept(Object x);
}
Modify the implementation of the
DataSet
class in
Section 9.4
to use
both a
Measurer
and a
Filter
object. Only objects that the filter
accepts should be processed. Demonstrate your modification by having a
data set process a collection of bank accounts, filtering out all accounts
with balances less than $1,000.
Exercise P9.9. Look up the definition of the standard
Comparable
interface in the API documentation. Modify the DataSet class of
Section
9.1
to accept
Comparable
objects. With this interface, it is no longer
meaningful to compute the average. The
DataSet
class should record the
minimum and maximum data values. Test your modified
DataSet
class