Java Reference
In-Depth Information
a.
An interface that will be used to specify the third parameter to
transform .
b.
The transform method (which is a static method). Remember to
throw an exception if the input and output arrays are not identically-
sized.
c.
The classes ComputeSquare and ComputeAbsoluteValue .
Rewrite Exercise 4.40 by using generics to allow the input array to be
of an arbitrary type.
4.42
Rewrite Exercise 4.41 by using generics to allow the input array and
output arrays to be of arbitrary (not necessarily the same) types.
4.43
This exercise asks you to write a generic countMatches method.
Your method will take two parameters. The first parameter is an
array of int . The second parameter is a function object that returns
a Boolean.
a. Give a declaration for an interface that expresses the requisite
function object.
b. countMatches returns the number of array items for which the
function object returns true . Implement countMatches .
4.44
c.
Test countMatches by writing a function object, EqualsZero , that
implements your interface to accept one parameter and returns
true if the parameter is equal to zero. Use an EqualsZero function
object to test countMatches .
Although the function objects we have looked at store no data, this is
not a requirement. Reuse the interface in Exercise 4.44(a).
a.
4.45
Write a function object EqualsK . EqualsK contains one data mem-
ber ( k ). EqualsK is constructed with a single parameter (the default
is zero) that is used to initialize k . Its method returns true if the
parameter is equal to k .
b.
Use EqualsK to test countMatches in Exercise 4.44 (c).
PROGRAMMING PROJECTS
4.46
Rewrite the Shape hierarchy to store the area as a data member and
have it computed by the Shape constructor. The constructors in the
derived classes should compute an area and pass the result to the
super method. Make area a final method that returns only the value of
this data member.
Add the concept of a position to the Shape hierarchy by including
coordinates as data members. Then add a distance method.
4.47
Write an abstract class for Date and its derived class GregorianDate .
4.48
Search WWH ::




Custom Search