1 import java.awt.Rectangle;
2
3 /**
4 This program demonstrates the use of an inner class.
5 */
6 public class DataSetTester3
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, 15));
28
29 System.out.println("Average area: " + data.getAverage());
30 System.out.println("Expected: 625");
31
32 Rectangle max = (Rectangle) data.getMaximum();
33 System.out.println("Maximum area rectangle: " + max);
34 System.out.println("Expected: "
35 + "java.awt.Rectangle[x=10,y=20,width=30,height=40]");
36 }
37 }