Question: E7.9 Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maximumNumberOfValues) and a method public void

E7.9 Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maximumNumberOfValues) and a method public void add(double value) that adds a value, provided there is still room. Provide methods to compute the sum, average, maximum, and minimum value.

/** * Code for E7.9 * @author */ public class DataSet { // Implmentation . . .

/** Constructs an empty data set. @param maximumNumberOfValues the maximum this data set can hold */ public DataSet(int maximumNumberOfValues) { . . . }

/** Adds a data value to the data set if there is room in the array. @param value a data value */ public void add(double value) { . . . }

/** Gets the sum of the added data. @return sum of the data or 0 if no data has been added */ public double getSum() { . . . }

/** Gets the average of the added data. @return average of the data or 0 if no data has been added */ public double getAverage() { . . . }

/** Gets the maximum value entered. @return maximum value of the data NOTE: returns -Double.MAX_VALUE if no values are entered. */ public double getMaximum() { . . . }

/** Gets the minimum value entered. @return minimum value of the data NOTE: returns Double.MAX_VALUE if no values are entered. */ public double getMinimum() { . . . } }

-----

Here are some ran tests for the Data Set

/** Run some tests for the DataSet class */ public class DataSetTester { public static void main(String[] args) { DataSet data = new DataSet(5); data.add(3.5); data.add(7.9); data.add(15.2); data.add(-7.3);

System.out.println("Sum: " + data.getSum()); System.out.println("Expected: 19.3"); System.out.println("Average: " + data.getAverage()); System.out.println("Expected: 4.825"); System.out.println("Maximum: " + data.getMaximum()); System.out.println("Expected: 15.2"); System.out.println("Minimum: " + data.getMinimum()); System.out.println("Expected: -7.3"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!