Java Reference
In-Depth Information
Write generic method min , which accepts an array and returns the
smallest item. Then use the method on the String type.
4.24
Write generic method max2 , which accepts an array and returns an
array of length two representing the two largest items in the array.
The input array should be unchanged. Then use this method on the
String type.
4.25
Write generic method sort , which accepts an array and rearranges the
array in nondecreasing sorted order. Test your method on both String
and BigInteger .
4.26
For the Shape example, modify the constructors in the hierarchy to
throw an InvalidArgumentException when the parameters are negative.
4.27
Add an Ellipse class into the Shape hierarchy, and make it Stretchable .
4.28
Modify the MemoryCell to implement Comparable<MemoryCell> .
4.29
Modify the Circle class to implement Comparable<Circle> .
4.30
Modify the BigRational class from Chapter 3 to implement Compara-
ble<BigRational> .
4.31
Modify the Polynomial class from Exercise 3.33 to implement Compa-
rable<Polynomial> . The comparison should be based on the degrees of
the polynomials.
4.32
Add a Square class into the Shape hierarchy, and have it implement
Comparable<Square> .
4.33
Add a Triangle class into the Shape hierarchy. Make it Stretchable , but
have stretch throw an exception if the call to stretch would result in
dimensions that violate the triangle inequality.
4.34
Revise the stretchAll method to accept a ArrayList instead of an
array. Use wildcards to ensure that both ArrayList<Stretchable> and
ArrayList<Rectangle> are acceptable parameters.
4.35
Modify the Person class so that it can use findMax to obtain the alpha-
betically last person.
4.36
A SingleBuffer supports get and put : The SingleBuffer stores a single
item and an indication whether the SingleBuffer is logically empty. A
put may be applied only to an empty buffer, and it inserts an item into
the buffer. A get may be applied only to a nonempty buffer, and it
deletes and returns the contents of the buffer. Write a generic class to
implement SingleBuffer . Define an exception to signal errors.
4.37
Search WWH ::




Custom Search