1 |
import java.awt.Rectangle; |
2 |
|
3 |
/** |
4 |
This program demonstrates the use of a Measurer. |
5 |
*/ |
6 |
public class DataSetTest |
7 |
{ |
8 |
public static void main(String[] args) |
9 |
{ |
10 |
class RectangleMeasurer implements Measurer |
11 |
{ |
12 |
public double measure(Object anObject) |
13 |
{ |
14 |
Rectangle aRectangle = (Rectangle)anObject; |
15 |
double area |
16 |
= aRectangle.getWidth() * aRectangle.getHeight(); |
17 |
return area; |
18 |
} |
19 |
} |
20 |
|
21 |
Measurer m = new RectangleMeasurer(); |
22 |
|
23 |
DataSet data = new DataSet(m); |
24 |
|
25 |
data.add(new Rectangle(5, 10, 20, 30)); |
26 |
data.add(new Rectangle(10, 20, 30, 40)); |
27 |
data.add(new Rectangle(20, 30, 5, 10)); |
28 |
|
29 |
System.out.println("Average area = " + data.getAverage()); |
30 |
Rectangle max = (Rectangle)data.getMaximum(); |
31 |
System.out.println("Maximum area = " + max); |
32 |
} |
33 |
} |