Question: Java Add a method to the Data class that returns the object with the largest measure, as measured by the supplied measurer. public static Object
Java
Add a method to the Data class that returns the object with the largest measure, as measured by the supplied measurer. public static Object max(Object[] objects, Measurer m)
public class Data
{
public static double average (Measurable[] objects)
{
double sum = 0;
for (Measurable obj : objects)
{
sum = sum + obj.getMeasure();
}
if(objects.length > 0) {return sum / objects.length;}
return 0;
}
public static double average(Object[] objects, Measurer meas)
{
double sum = 0;
for (Object obj : objects)
{
sum = sum + meas.measure(obj);
}
if (objects.length > 0) {return sum/objects.length;}
else {return 0;}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
