Java Reference
In-Depth Information
23 System.out.println(
"Expected:
java.awt.Rectangle[
24
x=10,y=20,width=30,height=40]"
);
25 }
26 }
401
402
ch09/measure2/Measurer.java
1 /**
2
Describes any class whose objects can measure other objects.
3 */
4
public interface
Measurer
5 {
6 /**
7
Computes the measure of an object.
8 @param anObject
the object to be measured
9 @return
the measure
10 */
11
double
measure(Object anObject);
12 }
ch09/measure2/RectangleMeasurer.java
1
import
java.awt.Rectangle;
2
3 /**
4
Objects of this class measure rectangles by area.
5 */
6
public class
RectangleMeasurer
implements
Measurer
7 {
8
public double
measure(Object anObject)
9 {
10 Rectangle aRectangle = (Rectangle)
anObject;
11
double
area = aRectangle.getWidth() *
aRectangle.getHeight();
12
return
area;
13 }
14 }