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 assort FactsDetermined that stores a enumerate of treasures of stamp embrace. Provide a constructor

    public FactsSet(int zenithNumberOfValues)

    and a method

    public unfilled gather(embrace treasure)

    that gathers a treasure, granted there is stagnant admission

    Provide methods to treasure the complete, middle, zenith, and poverty treasure.

    Heres what I insufficiency to use:

    public assort FactsSet

    {
    // Implmentation
    . . .

    /**
    Constructs an space facts determined.
    @param zenithNumberOfValues the zenith this facts determined can hold
    */
    public FactsSet(int zenithNumberOfValues)
    {
    . . .
    }

    /**
    Adds a facts treasure to the facts determined if there is admission in the accoutre.
    @param treasure a facts treasure
    */
    public unfilled gather(embrace treasure)
    {
    . . .
    }

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

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

    /**
    Gets the zenith treasure entered.
    @return zenith treasure of the facts
    NOTE: receipts -Double.MAX_VALUE if no treasures are entered.
    */
    public embrace getMaximum()
    {
    . . .
    }

    /**
    Gets the poverty treasure entered.
    @return poverty treasure of the facts
    NOTE: receipts Embrace.MAX_VALUE if no treasures are entered.
    */
    public embrace getMinimum()
    {
    . . .
    }
    }

    Thank you!

    Expert Tally

     

    DataSetTester.java
    ————————————————–
    public assort FactsSetTester {
    public static unfilled main (String args[])
    {
    DataDetermined facts = fantasticlightlight FactsSet(5);
    data.add(3.5);
    data.add(7.9);
    data.add(15.2);
    data.add(-7.3);

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

    {
    // Implmentation
    double[] facts;

    int pos;

    /**
    Constructs an space facts determined.
    @param zenithNumberOfValues the zenith this facts determined can hold
    */
    public FactsSet(int zenithNumberOfValues) {
    facts = fantasticlightlight embrace[maximumNumberOfValues];

    }

    /**
    Adds a facts treasure to the facts determined if there is admission in the accoutre.
    @param treasure a facts treasure
    */
    public unfilled gather(embrace treasure)
    {

    if (pos < facts.length){
    data[pos] = treasure;
    pos++;
    }

    }

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

    }
    return complete;
    }

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

    /**
    Gets the zenith treasure entered.
    @return zenith treasure of the facts
    NOTE: receipts -Double.MAX_VALUE if no treasures are entered.
    */
    public embrace getMaximum()
    {
    if (data.protraction ==0)
    return Embrace.MAX_VALUE;
    else {
    embrace max = facts[0];
    for (int i = 1; i < pos; i++) {
    if (max < facts[i])
    max = facts[i];
    }
    return max;
    }

    }

    /**
    Gets the poverty treasure entered.
    @return poverty treasure of the facts
    NOTE: receipts Embrace.MAX_VALUE if no treasures are entered.
    */
    public embrace getMinimum()
    {
    if (data.protraction == 0)
    return Embrace.MAX_VALUE;
    else {
    embrace min = facts[0];
    for (int i = 1; i < pos; i++) {
    if (min > facts[i])
    min = facts[i];

    }
    return min;
    }
    }

    }