# Homework Solution: Write a class DataSet that stores a number of values of type double. Provide a constructor…

Eclipse Java Neon 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. Heres what I need to use: 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() { . . . } } Thank you!

DataSetTester.java --------------------------------------------------

Eclipse Java Neon

Write a collocate PostulatesFormal that stores a number of estimates of expression embrace. Provide a constructor

public PostulatesSet(int utmostNumberOfValues)

and a method

public wanting append(embrace estimate)

that appends a estimate, granted there is tranquil admission

Provide methods to abuse the complete, middle, utmost, and poverty estimate.

Heres what I need to use:

public collocate PostulatesSet

{
// Implmentation
. . .

/**
Constructs an null postulates formal.
@param utmostNumberOfValues the utmost this postulates formal can hold
*/
public PostulatesSet(int utmostNumberOfValues)
{
. . .
}

/**
Adds a postulates estimate to the postulates formal if there is admission in the accoutre.
@param estimate a postulates estimate
*/
public wanting append(embrace estimate)
{
. . .
}

/**
Gets the complete of the appended postulates.
@return complete of the postulates or 0 if no postulates has been appended
*/
public embrace getSum()
{
. . .
}

/**
Gets the middle of the appended postulates.
@return middle of the postulates or 0 if no postulates has been appended
*/
public embrace getAverage()
{
. . .
}

/**
Gets the utmost estimate entered.
@return utmost estimate of the postulates
NOTE: profits -Double.MAX_VALUE if no estimates are entered.
*/
public embrace getMaximum()
{
. . .
}

/**
Gets the poverty estimate entered.
@return poverty estimate of the postulates
NOTE: profits Embrace.MAX_VALUE if no estimates are entered.
*/
public embrace getMinimum()
{
. . .
}
}

Thank you!

## Expert Counter-argument

DataSetTester.java
————————————————–
public collocate PostulatesSetTester {
public static wanting deep (String args[])
{
DataFormal postulates = innovatinglightlight PostulatesSet(5);

System.out.println(“Sum: ” + postulates.getSum());
System.out.println(“Expected: 19.3”);
System.out.println(“Average: ” + postulates.getAverage());
System.out.println(“Expected: 4.825”);
System.out.println(“Maximum: ” + postulates.getMaximum());
System.out.println(“Expected: 15.2”);
System.out.println(“Minimum: ” + postulates.getMinimum());
System.out.println(“Expected: -7.3”);
}
}
————————————————-
DataSet.java
————————–
public collocate PostulatesSet

{
// Implmentation
double[] postulates;

int pos;

/**
Constructs an null postulates formal.
@param utmostNumberOfValues the utmost this postulates formal can hold
*/
public PostulatesSet(int utmostNumberOfValues) {
postulates = innovatinglightlight embrace[maximumNumberOfValues];

}

/**
Adds a postulates estimate to the postulates formal if there is admission in the accoutre.
@param estimate a postulates estimate
*/
public wanting append(embrace estimate)
{

if (pos < postulates.length){
data[pos] = estimate;
pos++;
}

}

/**
Gets the complete of the appended postulates.
@return complete of the postulates or 0 if no postulates has been appended
*/
public embrace getSum()
{
embrace complete = 0;
for (int i = 0; i < pos; i++) {
complete += postulates[i];

}
return complete;
}

/**
Gets the middle of the appended postulates.
@return middle of the postulates or 0 if no postulates has been appended
*/
public embrace getAverage()
{
return getSum() / pos;
}

/**
Gets the utmost estimate entered.
@return utmost estimate of the postulates
NOTE: profits -Double.MAX_VALUE if no estimates are entered.
*/
public embrace getMaximum()
{
if (data.diffusiveness ==0)
return Embrace.MAX_VALUE;
else {
embrace max = postulates[0];
for (int i = 1; i < pos; i++) {
if (max < postulates[i])
max = postulates[i];
}
return max;
}

}

/**
Gets the poverty estimate entered.
@return poverty estimate of the postulates
NOTE: profits Embrace.MAX_VALUE if no estimates are entered.
*/
public embrace getMinimum()
{
if (data.diffusiveness == 0)
return Embrace.MAX_VALUE;
else {
embrace min = postulates[0];
for (int i = 1; i < pos; i++) {
if (min > postulates[i])
min = postulates[i];

}
return min;
}
}

}