Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class SimpleStats { public static void main(String[] args) { StatCalc cal

ID: 3668529 • Letter: P

Question


public class SimpleStats {
   public static void main(String[] args) {

StatCalc calc;
calc = new StatCalc();

double item;   

System.out.println("Enter your numbers:");
System.out.println();

do {
   System.out.println("? ");

item = TextIO.getlnDouble();
if (item != 0)
calc.enter(item);
} while ( item != 0 );



System.out.println(" Minimum: " + calc.getMin());
System.out.println(" Maximum: " + calc.getMax());
System.out.println(" Mean: " + calc.getMean());
System.out.println(" Standard Deviation: " + calc.getStandardDeviation());

}
  
}

  


public class StatCalc {

private int count; // Number of numbers that have been entered.
private double sum; // The sum of all the items that have been entered.
private double squareSum; // The sum of the squares of all the items.
private double max = Double.NEGATIVE_INFINITY; // Largest item seen.
private double min = Double.POSITIVE_INFINITY; // Smallest item seen.

public void enter(double num) {
// Add the number to the dataset.
count++;
sum += num;
squareSum += num*num;
if (num > max)
max = num;
if (num < min)
min = num;
}

public int getCount() {   

return count;
}

public double getSum() {
  
return sum;
}

public double getMean() {
  
return sum / count;
}

public double getStandardDeviation() {
  
double mean = getMean();
return Math.sqrt( squareSum/count - mean*mean );
}
  
public double getMin() {

return min;
}
  
public double getMax() {

return max;
}

}

Help! The  item = TextIO.getlnDouble(); isn;t working. Im suppose to enter numbers and than have the max, min, stdev, and mkean calculate & this line isn't working.

Explanation / Answer

In this Code you have mistake like sqrt function paranthesis i changed, and TextIo one class is created for getdoubleIn, then i copied two classes here, there is no error

Answer:

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package simplestats;

/**

*

* @author HARE KRISHNA

*/

class SimpleStats {

    /**

     * @param args the command line arguments

     */

            public static void main(String[] args) {

            StatCalc calc;

            calc = new StatCalc();

            double item;

            System.out.println("Enter your numbers:");

            System.out.println();

            do {

                System.out.println("? ");

                 item = TextIO.getlnDouble();

                 if (item != 0)

                     calc.enter(item);

            } while ( item != 0 );

            System.out.println(" Minimum: " + calc.getMin());

            System.out.println(" Maximum: " + calc.getMax());

            System.out.println(" Mean: " + calc.getMean());

            System.out.println(" Standard Deviation: " + calc.getStandardDeviation());

}

}

class StatCalc {

            private int count; // Number of numbers that have been entered.

           private double sum; // The sum of all the items that have been entered.

            private double squareSum; // The sum of the squares of all the items.

            private double max = Double.NEGATIVE_INFINITY; // Largest item seen.

            private double min = Double.POSITIVE_INFINITY; // Smallest item seen.

            public void enter(double num) {

// Add the number to the dataset.

            count++;

            sum += num;

            squareSum += num*num;

            if (num > max)

                max = num;

            if (num < min)

                min = num;

            }

            public int getCount() {

                return count;

            }

            public double getSum() {

                    return sum;

        }

            public double getMean() {

                return sum / count;

}

            public double getStandardDeviation() {

                double mean = getMean();

                return Math.sqrt((squareSum/count)-(mean*mean));

}

            public double getMin() {

                return min;

}

            public double getMax() {

                return max;

}

}

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package simplestats;

/**

*

* @author HARE KRISHNA

*/

class TextIO {

    static double getlnDouble() {

        throw new UnsupportedOperationException("Not yet implemented");

    }

}