Java Reference
In-Depth Information
You also can run the program without the year. In this case, the year is the current
year. If you run the program without specifying a month and a year, the month is
the current month.
Sections 13.4-13.8
*13.5
( Enable GeometricObject comparable ) Modify the GeometricObject class
to implement the Comparable interface, and define a static max method in the
GeometricObject class for finding the larger of two GeometricObject objects.
Draw the UML diagram and implement the new GeometricObject class. Write
a test program that uses the max method to find the larger of two circles and the
larger of two rectangles.
*13.6
( The ComparableCircle class ) Define a class named ComparableCircle
that extends Circle and implements Comparable . Draw the UML diagram and
implement the compareTo method to compare the circles on the basis of area.
Write a test class to find the larger of two instances of ComparableCircle objects.
*13.7
( The Colorable interface ) Design an interface named Colorable with a void
method named howToColor() . Every class of a colorable object must imple-
ment the Colorable interface. Design a class named Square that extends
GeometricObject and implements Colorable . Implement howToColor to
display the message Color all four sides .
Draw a UML diagram that involves Colorable , Square , and GeometricObject .
Write a test program that creates an array of five GeometricObject s. For each
object in the array, display its area and invoke its howToColor method if it is
colorable.
*13.8
( Revise the MyStack class ) Rewrite the MyStack class in Listing 11.10 to perform
a deep copy of the list field.
*13.9
( Enable Circle comparable ) Rewrite the Circle class in Listing 13.2 to extend
GeometricObject and implement the Comparable interface. Override the
equals method in the Object class. Two Circle objects are equal if their radii
are the same. Draw the UML diagram that involves Circle , GeometricObject ,
and Comparable .
*13.10
( Enable Rectangle comparable ) Rewrite the Rectangle class in Listing 13.3 to
extend GeometricObject and implement the Comparable interface. Override
the equals method in the Object class. Two Rectangle objects are equal
if their areas are the same. Draw the UML diagram that involves Rectangle ,
GeometricObject , and Comparable .
VideoNote
Redesign the Rectangle
class
*13.11
( The Octagon class ) Write a class named Octagon that extends
GeometricObject and implements the Comparable and Cloneable inter-
faces. Assume that all eight sides of the octagon are of equal length. The area can
be computed using the following formula:
area
=
(2
+
4/
2
2)* side * side
Draw the UML diagram that involves Octagon , GeometricObject ,
Comparable , and Cloneable . Write a test program that creates an Octagon
object with side value 5 and displays its area and perimeter. Create a new object
using the clone method and compare the two objects using the compareTo
method.
*13.12
( Sum the areas of geometric objects ) Write a method that sums the areas of all the
geometric objects in an array. The method signature is:
public static double sumArea(GeometricObject[] a)
 
Search WWH ::




Custom Search