public class Averager
extends java.lang.Object
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 and Description |
|---|
Averager()
Initialize an
Averager. |
| Modifier and Type | Method and Description |
|---|---|
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. |
public Averager()
Averager.
param - none
Postcondition:
This Averager has been initialized and is ready to accept numbers.public void addNumber(double value)
Averager.value - the next number to give to this Averager
Precondition:
howManyNumbers() < Integer.MAX_VALUE.
Postcondition:
This Averager has accepted value as the next number.java.lang.IllegalStateException - Indicates that howManyNumbers() is
Integer.MAX_VALUE.public double average()
Averager.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.public int howManyNumbers()
Averager.Averager