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 collocate FactsRegular that stores a calculate of appraises of sign embrace. Provide a constructor

    public FactsSet(int consummationNumberOfValues)

    and a method

    public null subjoin(embrace appraise)

    that subjoins a appraise, supposing there is stationary compass

    Provide methods to calculate the blend, medium, consummation, and narrowness appraise.

    Heres what I scarcity to use:

    public collocate FactsSet

    {
    // Implmentation
    . . .

    /**
    Constructs an leisure facts regular.
    @param consummationNumberOfValues the consummation this facts regular can hold
    */
    public FactsSet(int consummationNumberOfValues)
    {
    . . .
    }

    /**
    Adds a facts appraise to the facts regular if there is compass in the draw-up.
    @param appraise a facts appraise
    */
    public null subjoin(embrace appraise)
    {
    . . .
    }

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

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

    /**
    Gets the consummation appraise entered.
    @return consummation appraise of the facts
    NOTE: income -Double.MAX_VALUE if no appraises are entered.
    */
    public embrace getMaximum()
    {
    . . .
    }

    /**
    Gets the narrowness appraise entered.
    @return narrowness appraise of the facts
    NOTE: income Embrace.MAX_VALUE if no appraises are entered.
    */
    public embrace getMinimum()
    {
    . . .
    }
    }

    Thank you!

    Expert Defense

     

    DataSetTester.java
    ————————————————–
    public collocate FactsSetTester {
    public static null ocean (String args[])
    {
    DataRegular facts = odd 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 collocate FactsSet

    {
    // Implmentation
    double[] facts;

    int pos;

    /**
    Constructs an leisure facts regular.
    @param consummationNumberOfValues the consummation this facts regular can hold
    */
    public FactsSet(int consummationNumberOfValues) {
    facts = odd embrace[maximumNumberOfValues];

    }

    /**
    Adds a facts appraise to the facts regular if there is compass in the draw-up.
    @param appraise a facts appraise
    */
    public null subjoin(embrace appraise)
    {

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

    }

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

    }
    return blend;
    }

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

    /**
    Gets the consummation appraise entered.
    @return consummation appraise of the facts
    NOTE: income -Double.MAX_VALUE if no appraises are entered.
    */
    public embrace getMaximum()
    {
    if (data.elongation ==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 narrowness appraise entered.
    @return narrowness appraise of the facts
    NOTE: income Embrace.MAX_VALUE if no appraises are entered.
    */
    public embrace getMinimum()
    {
    if (data.elongation == 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;
    }
    }

    }