/** This class tests the DataSet class. */ public class DataSetTest { public static void main(String[] args) { Measurable [] accounts = { new BankAccount2(0), new BankAccount2(10000), new BankAccount2(2000) } ; Measurable max ; // will point to object with largest measure // create DataSet for bank accounts DataSet data = new DataSet(accounts) ; System.out.println("Average balance = " + data.getAverage()); max = data.getMaximum(); System.out.println("Highest balance = " + max.getMeasure()); // Play it, Sam. Play it again. Measurable [] coins = { new Coin(0.25, "quarter"), new Coin(0.1, "dime"), new Coin(0.05, "nickel") } ; // create new DataSet for coins data = new DataSet(coins); System.out.println("\nAverage coin value = " + data.getAverage()) ; max = data.getMaximum(); System.out.println("Highest coin value = " + max.getMeasure()) ; // Note to students: following is an example of a "downcast" of object // max from Measurable to Coin. This is required because method // getName() is present in Coin class but not in Measurable interface System.out.println("Coin with greatest value is a " + ((Coin)max).getName()) ; } } /* program output: Average balance = 4000.0 Highest balance = 10000.0 Average coin value = 0.13333333333333333 Highest coin value = 0.25 Coin with greatest value is a quarter */