Building Parsers with Java

sjm.examples.design
Class RunningAverage

java.lang.Object
  |
  +--sjm.examples.design.RunningAverage

public class RunningAverage
extends java.lang.Object
implements PubliclyCloneable

Objects of this class maintain a running average. Each number that is added with the add method increases the count by 1, and the total by the amount added.


Field Summary
protected  double count
           
protected  double total
           
 
Constructor Summary
RunningAverage()
           
 
Method Summary
 void add(double d)
          Add a value to the running average, increasing the count by 1 and the total by the given value.
 double average()
          Return the average so far.
 java.lang.Object clone()
          Return a copy of this object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected double count

total

protected double total
Constructor Detail

RunningAverage

public RunningAverage()
Method Detail

add

public void add(double d)
Add a value to the running average, increasing the count by 1 and the total by the given value.
Parameters:
double - the value to add into the running average

average

public double average()
Return the average so far.
Returns:
the average so far

clone

public java.lang.Object clone()
Return a copy of this object.
Specified by:
clone in interface PubliclyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy of this object

by Steve Metsker