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!

    Expert Answer

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

    Eclipse Java Neon

    Write a systematize PostulatesFixed that stores a estimate of rates of stamp inclose. Provide a constructor

    public PostulatesSet(int zenithNumberOfValues)

    and a method

    public unsubstantial supplement(inclose rate)

    that supplements a rate, granted there is stagnant space

    Provide methods to estimate the blend, mediocre, zenith, and stint rate.

    Heres what I demand to use:

    public systematize PostulatesSet

    {
    // Implmentation
    . . .

    /**
    Constructs an space postulates fixed.
    @param zenithNumberOfValues the zenith this postulates fixed can hold
    */
    public PostulatesSet(int zenithNumberOfValues)
    {
    . . .
    }

    /**
    Adds a postulates rate to the postulates fixed if there is space in the deck.
    @param rate a postulates rate
    */
    public unsubstantial supplement(inclose rate)
    {
    . . .
    }

    /**
    Gets the blend of the supplemented postulates.
    @return blend of the postulates or 0 if no postulates has been supplemented
    */
    public inclose getSum()
    {
    . . .
    }

    /**
    Gets the mediocre of the supplemented postulates.
    @return mediocre of the postulates or 0 if no postulates has been supplemented
    */
    public inclose getAverage()
    {
    . . .
    }

    /**
    Gets the zenith rate entered.
    @return zenith rate of the postulates
    NOTE: income -Double.MAX_VALUE if no rates are entered.
    */
    public inclose getMaximum()
    {
    . . .
    }

    /**
    Gets the stint rate entered.
    @return stint rate of the postulates
    NOTE: income Inclose.MAX_VALUE if no rates are entered.
    */
    public inclose getMinimum()
    {
    . . .
    }
    }

    Thank you!

    Expert Reply

     

    DataSetTester.java
    ————————————————–
    public systematize PostulatesSetTester {
    public static unsubstantial main (String args[])
    {
    DataFixed postulates = innovating PostulatesSet(5);
    data.add(3.5);
    data.add(7.9);
    data.add(15.2);
    data.add(-7.3);

    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 systematize PostulatesSet

    {
    // Implmentation
    double[] postulates;

    int pos;

    /**
    Constructs an space postulates fixed.
    @param zenithNumberOfValues the zenith this postulates fixed can hold
    */
    public PostulatesSet(int zenithNumberOfValues) {
    postulates = innovating inclose[maximumNumberOfValues];

    }

    /**
    Adds a postulates rate to the postulates fixed if there is space in the deck.
    @param rate a postulates rate
    */
    public unsubstantial supplement(inclose rate)
    {

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

    }

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

    }
    return blend;
    }

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

    /**
    Gets the zenith rate entered.
    @return zenith rate of the postulates
    NOTE: income -Double.MAX_VALUE if no rates are entered.
    */
    public inclose getMaximum()
    {
    if (data.protraction ==0)
    return Inclose.MAX_VALUE;
    else {
    inclose max = postulates[0];
    for (int i = 1; i < pos; i++) {
    if (max < postulates[i])
    max = postulates[i];
    }
    return max;
    }

    }

    /**
    Gets the stint rate entered.
    @return stint rate of the postulates
    NOTE: income Inclose.MAX_VALUE if no rates are entered.
    */
    public inclose getMinimum()
    {
    if (data.protraction == 0)
    return Inclose.MAX_VALUE;
    else {
    inclose min = postulates[0];
    for (int i = 1; i < pos; i++) {
    if (min > postulates[i])
    min = postulates[i];

    }
    return min;
    }
    }

    }