FileDocCategorySizeDatePackage
Averager.javaAPI DocExample2425Sat Jan 24 10:44:24 GMT 2004je3.classes

Averager

public class Averager extends Object
A class to compute the running average of numbers passed to it

Fields Summary
private int
n
private double
sum
private double
sumOfSquares
Constructors Summary
Methods Summary
public voidaddDatum(double x)
This method adds a new datum into the average.


                   
        
        n++;
        sum += x;
        sumOfSquares += x * x;
    
public doublegetAverage()
This method returns the average of all numbers passed to addDatum()

 return sum / n; 
public doublegetNum()
This method returns the number of numbers passed to addDatum()

 return n; 
public doublegetStandardDeviation()
This method returns the standard deviation of the data

          return Math.sqrt(((sumOfSquares - sum*sum/n)/n));
    
public doublegetSum()
This method returns the sum of all numbers passed to addDatum()

 return sum; 
public doublegetSumOfSquares()
This method returns the sum of the squares of all numbers.

 return sumOfSquares; 
public voidreset()
This method resets the Averager object to begin from scratch

 n = 0; sum = 0.0; sumOfSquares = 0.0;