/** * Computes the average and maximum of a set of data values */ public class DataSet { private Measurable [] list ; /** * Creates a DataSet object * @param objects an array of Measurable objects */ public DataSet(Measurable [] objects) { list = objects ; } /** * Gets the average measure of all objects in the list * @return the average or 0 if no data has been added */ public double getAverage() { return Measurable.getAverage(list) ; // calls static method } /** * Returns a pointer to the Measurable object with the largest measure in * the list * @return a pointer to object with the largest measure or null if the * the list is empty */ public Measurable getMaximum() { // if list is empty, nothing to return if (list.length == 0) return null ; Measurable max = list[0] ; for (Measurable nextObj : list) { if (nextObj.isGreaterThan(max)) // calls default method { max = nextObj ; } } return max ; } }