Data.java.html

  1  public class Data
  2  {
  3     /**
  4        Computes the average of the measures of the given objects.
  5        @param objects an array of objects
  6        @param meas the measurer for the objects
  7        @return the average of the measures
  8     */
  9     public static double average(Object[] objects, Measurer meas)
 10     {
 11        double sum = 0;
 12        for (Object obj : objects)
 13        {
 14           sum = sum + meas.measure(obj);
 15        }
 16        if (objects.length > 0) { return sum / objects.length; }
 17        else { return 0; }
 18     }
 19  }