Mean and standard deviation. Write a program that reads a set of floating-point data values from the input. When the user indicates the end of input, print out the count of the values, the average, and the standard deviation. The average of a data set x1,…,xn is

You can compute this quantity by keeping track of the count, the sum, and the sum of squares in the DataSet class as you process the input values.

Complete the following files:

DataAnalyzer.java

DataSet.java

/** This class is used to calculate the average and standard deviation of a data set. */ public class DataSet { private double sum; private double sumSquare; private int n; /** Constructs a DataSet object to hold the total number of inputs, the sum, and the sum of square. */ public DataSet() { . . . } /** Adds a value to this data set. @param x the input value */ public void add(double x) { sum = sum + x; sumSquare = sumSquare + x * x; n++; } /** Method used to calculate the average of the data set. @return average the average of the data set */ public double getAverage() { . . . } /** Method used to calculate the standard deviation. @return stddev the standard deviation of data set */ public double getStandardDeviation() { . . . } /** Gets the total number of input values. @return n the total number of inputs */ public int getCount() { . . . } }

Use the following file:

DataSetTester.java

import java.util.Scanner;

/**
   This is a test driver class for DataSet class.
*/
public class DataSetTester
{
   public static void main(String[] args)
   {
      DataSet a = new DataSet();
      a.add(5);
      a.add(6);
      a.add(8);
      a.add(9);
      System.out.println("count: " + a.getCount());
      System.out.println("Expected: 4");
      System.out.println("average: " + a.getAverage());
      System.out.println("Expected: 7");
      System.out.println("standard deviation: " + a.getStandardDeviation());
      System.out.println("Expected: 1.83");
   }
}