edu.colorado.simulations
Class Averager

java.lang.Object
  extended by edu.colorado.simulations.Averager

public class Averager
extends java.lang.Object

An Averager computes an average of a group of numbers.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/simulations/Averager.java


Constructor Summary
Averager()
          Initialize an Averager.
 
Method Summary
 void addNumber(double value)
          Give another number to this Averager.
 double average()
          Provide an average of all numbers given to this Averager.
 int howManyNumbers()
          Provide a count of how many numbers have been given to this Averager.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Averager

public Averager()
Initialize an Averager. param - none
Postcondition:
This Averager has been initialized and is ready to accept numbers.

Method Detail

addNumber

public void addNumber(double value)
Give another number to this Averager.

Parameters:
value - the next number to give to this Averager
Precondition:
howManyNumbers() < Integer.MAX_VALUE.
Postcondition:
This Averager has accepted value as the next number.
Throws:
java.lang.IllegalStateException - Indicates that howManyNumbers() is Integer.MAX_VALUE.

average

public double average()
Provide an average of all numbers given to this Averager.

Parameters:
- - none
Returns:
the average of all the numbers that have been given to this Averager the next number to give to this Averager
Postcondition:
If howManyNumbers() is zero, then the answer is Double.NaN ("not a number"). The answer may also be Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY if there has been an arithmetic overflow during the summing of all the numbers.

howManyNumbers

public int howManyNumbers()
Provide a count of how many numbers have been given to this Averager.

Parameters:
- - none
Returns:
the count of how many numbers have been given to this Averager