generic lab solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

generic lab

Start with the DataSet class and make it into a generic DataSetGen class. Test it with the DataSetTester. The DataSetTester uses the BankAccount and BaseballPlayer classes. Do not change any of the classes except DataSet. Upload your DataSetGen.java

dataset

/**
Computes the average of a set of data values.
*/
public class DataSet
{
private double sum;
private Measurable maximum;
private int count;

/**
Constructs an empty data set.
*/
public DataSet()
{
sum = 0;
count = 0;
maximum = null;
}

/**
Adds a data value to the data set.
@param x a data value
*/
public void add(Measurable x)
{
sum = sum + x.getMeasure();
if (count == 0 || maximum.getMeasure() < x.getMeasure())
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 Measurable getMaximum()
{
return maximum;
}
}