//An instance of this class represents a set of Objects // that implement the Measurable interface: // double getMeasure() // //A DataSet instance provides the following functionality: // // DataSet() - default constructor creates an empty DataSet // void add(Measurable obj) - add a Measurable to this DataSet // int getNumber() - the # of Measurables in this DataSet // double getAverage() - the average of the Measurables this DataSet // Measurable getMaximum() - the largest Measurable of this DataSet // //This implementation is a variation of an example from p466 of // the the textbook, Big Java - Cay Horstman - 5th ed. // based on implementation of earlier editions // public class DataSet { //Instance Variables private int number; //Number of Measurables in this DataSet private double total; //Total of all Measurables (balances) in this DataSet private Measurable maximum; //Largest Measurable in this DataSet //Default Constructor public DataSet() { this.number = 0; this.total = 0.0; this.maximum = null; } //Accessor public int getNumber() { return this.number; } //Accessor public double getAverage() { if (this.number == 0) return 0.0; else return this.total / this.number; } //Accessor public Measurable getMaximum() { return this.maximum; } //Mutator: Add another item to the Data Set public void add(Measurable item) { this.number++; this.total += item.getMeasure(); if (this.number == 1 || item.getMeasure() > this.maximum.getMeasure()) this.maximum = item; } }