import java.awt.Rectangle; /** Another version of DataSetTester3.java (Horstmann chapter 9). Modified to use anonymous inner class and anonymous Measurer object, by cmc, 11/6/03, and small changes 2/18/05. */ public class DataSetTester_anon { public static void main(String[] args) { DataSet data = new DataSet( new Measurer() { // define anonymous class to implement Measurer public double measure(Object anObject) { Rectangle r = (Rectangle)anObject; double area = r.getWidth() * r.getHeight(); return area; } } // end of anonymous class - a Measurer object is constructed ); // end of call to DataSet constructor data.add(new Rectangle(5, 10, 20, 30)); data.add(new Rectangle(10, 20, 30, 40)); data.add(new Rectangle(20, 30, 5, 10)); System.out.println("Average area = " + data.getAverage()); Rectangle max = (Rectangle)data.getMaximum(); System.out.println("Maximum area = " + max); } }