HELP ME PLEASE. I AM A 1ST YR COLLEGE STUDENT :/
Define an interface Filter as follows:
public interface Filter
{
boolean accept(Object x);
}
Modify the implementation of the DataSet class to use both a Measurer and a Filter object. Only objects
that the filter accepts should be processed. Demonstrate your modification by having a data set process
a collection of bank accounts, filtering out all accounts with balances less than $1,000.
Refer to the source code below:
/**
Computes the average of a set of data values.
*/
public class DataSet {
private double sum;
private Object maximum;
private int count;
private Measurer measurer;
//Constructs an empty data set with a given measurer.
//@param aMeasurer the measurer that is used to measure
//data values
public DataSet(Measurer aMeasurer) {
sum = 0;
count = 0;
maximum = null;
measurer = aMeasurer;
}
//Adds a data value to the data set.
//@param xa data value
public void add(Object x){
sum = sum + measurer.measure(x);
if (count == 0 | | measurer.measure(maximum) < measurer.measure(x))
maximum = x;
count++;
}//Gets the average of the added data.
//@return the average or 0 if no data has been added
public double getAverage(){
if (count == 0) return 0;
else
return sum / count;
}
//Gets the largest of the added data.
//@return the maximum or 0 if no data has been added
public Object getMaximum(){
return maximum;
}
}