Question

The following class StatCalc defines a series of methods for computing statistics for a group of...


The following class StatCalc defines a series of methods for computing statistics for a group of numbers.

 /*
 * An object of class StatCalc can be used to compute several simple statistics
 * for a set of numbers.  Numbers are entered into the dataset using
 * the enter(double) method.  Methods are provided to return the following
 * statistics for the set of numbers that have been entered: The number
 * of items, the sum of the items, the average, and the standard deviation
 */
 
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.
 
   /**
    * Add a number to the dataset.  The statistics will be computed for all
    * the numbers that have been added to the dataset using this method.
    */
   public void enter(double num) {
          count++;
          sum += num;
          squareSum += num*num;
   }
 
   /**
    * Return the number of items that have been entered into the dataset.
    */
   public int getCount() {
          return count;
   }
 
   /**
    * Return the sum of all the numbers that have been entered.
    */
   public double getSum() {
          return sum;
   }
 
   /**
    * Return the average of all the items that have been entered.
    * The return value is Double.NaN if no numbers have been entered.
   */
   public double getMean() {
          return sum / count;
   }
 
   /**
    * Return the standard deviation of all the items that have been entered.
    * The return value is Double.NaN if no numbers have been entered.
    */
   public double getStandardDeviation() {
          double mean = getMean();
          return Math.sqrt( squareSum/count - mean*mean );
   }         
}  // end class StatCalc

Using the StatCalc class, write a program that calculates and then displays as output to the console, the following statistics against the set of numbers given below.

Statistics that must be calculated:

  • Count – Quantity of numbers in the data set.
  • Mean – The mean or average of the numbers in the data set.
  • Standard Deviation – The measure of variance (or dispersion) from the mean.

The set of numbers that you must use is as follows:

5 7 12 23 3 2 8 14 10 5 9 13

You must create a program with a main method that defines the StatCalc class and instantiates an instance of StatCalc called myStatCalc. Your program should instantiate the instance of the StatCalc using a statement similar to the following:

StatCalc myStatCalc;
myStatCalc = new StatCalc();
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Program has been posted here:

/*
* An object of class StatCalc can be used to compute several simple statistics
* for a set of numbers. Numbers are entered into the dataset using
* the enter(double) method. Methods are provided to return the following
* statistics for the set of numbers that have been entered: The number
* of items, the sum of the items, the average, and the standard deviation
*/

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.

/**
* Add a number to the dataset. The statistics will be computed for all
* the numbers that have been added to the dataset using this method.
*/
public void enter(double num) {
count++;
sum += num;
squareSum += num*num;
}

/**
* Return the number of items that have been entered into the dataset.
*/
public int getCount() {
return count;
}

/**
* Return the sum of all the numbers that have been entered.
*/
public double getSum() {
return sum;
}

/**
* Return the average of all the items that have been entered.
* The return value is Double.NaN if no numbers have been entered.
*/
public double getMean() {
return sum / count;
}

/**
* Return the standard deviation of all the items that have been entered.
* The return value is Double.NaN if no numbers have been entered.
*/
public double getStandardDeviation() {
double mean = getMean();
return Math.sqrt( squareSum/count - mean*mean );
}   

// Main Method
public static void main(String[] args) {

        //Instance of the Class StatCalc
       StatCalc mystatCalc;
       mystatCalc = new StatCalc();
      
       //Array list as given in the question
       int[] array = new int[] {5, 7, 12, 23, 3, 2, 8, 14, 10, 5, 9, 13};
       int n = array.length;
      
       //Calling enter method to calculate count, sum, mean and Standard Deviation
       for(int i=0;i<n;i++){
           mystatCalc.enter(array[i]);
       }
       //Count – Quantity of numbers in the data set.
       System.out.println("Count = " + mystatCalc.getCount());
      
       //Mean – The mean or average of the numbers in the data set.
       System.out.println("Mean = " + mystatCalc.getMean());
      
       //Standard Deviation – The measure of variance (or dispersion) from the mean.
       System.out.println("Standard Deviation = "+mystatCalc.getStandardDeviation());
      

   }
}

Output screenshot:

  

Code Screenshot:

If you need any help regarding this answer please let me know.

Add a comment
Know the answer?
Add Answer to:
The following class StatCalc defines a series of methods for computing statistics for a group of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following class StatCalc defines a series of methods for computing statistics for a group of...

    The following class StatCalc defines a series of methods for computing statistics for a group of numbers. /* * An object of class StatCalc can be used to compute several simple statistics * for a set of numbers. Numbers are entered into the dataset using * the enter(double) method. Methods are provided to return the following * statistics for the set of numbers that have been entered: The number * of items, the sum of the items, the average, and...

  • Write the definitions of the member functions of the class integerManipulation not given in Example 10-11....

    Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class: Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have ndigits. If needed add additional instance variables.) Determine the number of zeroes. Determine the number of even digits. Determine the number of odd digits Also, write a...

  • The FoodItem.java file defines a class called FoodItem that contains instance variables for name (String) and...

    The FoodItem.java file defines a class called FoodItem that contains instance variables for name (String) and calories (int), along with get/set methods for both. Implement the methods in the Meal class found in Meal.java public class FoodItem{ private String name; private int calories;    public FoodItem(String iName, int iCals){ name = iName; calories = iCals; }    public void setName(String newName){ name = newName; }    public void setCalories(int newCals){ calories = newCals; }    public int getCalories(){ return calories;...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • ble and instance variable, and then use clas 4. Please discuss the difference between class variable...

    ble and instance variable, and then use clas 4. Please discuss the difference between class variable and instant variable to complete the following code for the count of number of stud public class Student _//q1: fill this line to create a class variable num. public Student 1/ 22: fill this line to increase num. public static int getNum() return num; public static void main(String[] args) { Student stl=new Student O; Student st2-new Student ; Student st3-new Student ; //q3: fill...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • Your output should look as follows: DataSet = 10, 27, 32, 34, 35, 44, 48, 49...

    Your output should look as follows: DataSet = 10, 27, 32, 34, 35, 44, 48, 49 Descriptive Statistics: Minimum Maximum Range Size Sum Mean Median Standard Deviation Variance Mid Range = 10 = 49 = 39 = 8 = 279 = 34.875000 = 39.500000 = 12.788806 = 163.553571 = 29.5 Enter a integer value to be set in the DataSet: 50 Enter a valid index from the DataSet: 1 DataSet = 10, 32, 34, 35, 44, 48, 49, 50 Value...

  • We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private...

    We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private int x = 0; // constructor public Class1(int x) { this.x = x; } // instance methods public double myMethod1(double x, double y) { return x - y; } public void myMethod2(int x) { System.out.println(x); } public String myMethod3(String x) { return "hi " + x; } } We have also written the following Class2 class: class Class2 implements SecretInterface { // instance variable...

  • The following code below must be able to run using linked list instead of using arrays...

    The following code below must be able to run using linked list instead of using arrays ------------------------------------------------------------------------------------------------------- #include #include using namespace std; //Class for standard deviation class stdDev { private:        int max;        double value[100];        double mean; public:        double CalMean()        {               double sum = 0;               for (int i = 0; i < max; i++)                      sum += value[i];               return (sum / max);        }        double CalVariane()        {               mean = CalMean();...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT