edu.colorado.homework
Class Statistician

java.lang.Object
  extended by edu.colorado.homework.Statistician

public class Statistician
extends java.lang.Object

This class is a homework assignment; A Statistician keeps track of statistics about a sequence of double numbers.

Note:
This file contains only blank implementations ("stubs") because this is a Programming Project for my students.
Outline of Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/homework/Statistician.java


Constructor Summary
Statistician()
          Initialize a new Statistician.
 
Method Summary
 void addAll(Statistician addend)
          Add the numbers of another Statistician to this Statistician.
 void clear()
          Clear this Statistician.
 boolean equals(java.lang.Object obj)
          Compare this Statistician to another object for equality.
 int length()
          Determine how many numbers have been given to this Statistician.
 double maximum()
          Determine the largest number that has been given to this Statistician.
 double mean()
          Determine the arithmetic average of all the numbers that have been given to this Statistician.
 double minimum()
          Determine the smallest number that has been given to this Statistician.
 void next(double number)
          Give a new number to this Statistician.
 double sum()
          Determine the sum of all the numbers that have been given to this Statistician.
static Statistician union(Statistician s1, Statistician s2)
          Create a new Statistician that behaves as if it was given all the numbers from two other bags.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Statistician

public Statistician()
Initialize a new Statistician.

Parameters:
- - none
Postcondition:
This Statistician is newly initialized and has not yet been given any numbers.
Method Detail

addAll

public void addAll(Statistician addend)
Add the numbers of another Statistician to this Statistician.

Parameters:
addend - a Statistician whose numbers will be added to this Statistician
Precondition:
The parameter, addend, is not null.
Postcondition:
The numbers from addend have been added to this Statistician. After the operation, this Statistician acts as if if was given all of its numbers and also given all of the numbers from the addend.
Throws:
java.lang.NullPointerException - Indicates that addend is null.

clear

public void clear()
Clear this Statistician.

Parameters:
- - none
Postcondition:
This Statistician is reinitialized as if it has never been given any numbers.

equals

public boolean equals(java.lang.Object obj)
Compare this Statistician to another object for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object with which this Statistician will be compared
Returns:
A return value of true indicates that obj refers to a Statistican object with the same length, sum, mean, minimum and maximum as this Statistician. Otherwise the return value is false.
Note:
If obj is null or does not refer to a Statistician object, then the answer is false.

length

public int length()
Determine how many numbers have been given to this Statistician.

Parameters:
- - none
Returns:
the count of how many numbers have been given to this Statistician since it was initialized or reinitialized.
Note:
Giving a Statistician more than Integer.MAX_VALUE numbers, will cause failure with an arithmetic overflow.

maximum

public double maximum()
Determine the largest number that has been given to this Statistician.

Parameters:
- - none
Returns:
the largest number that has been given to this Statistician since it was initialized or reinitialized.
Note:
If length() is zero, then the answer from this method is Double.NaN.

mean

public double mean()
Determine the arithmetic average of all the numbers that have been given to this Statistician.

Parameters:
- - none
Returns:
the arithmetic mean of all the number that have been given to this Statistician since it was initialized or reinitialized.
Note:
If this Statistician has been given more than Integer.MAX_VALUE numbers, then this method fails because of arithmetic overflow. If length() is zero, then the answer from this method is Double.NaN. If sum() exceeds the bounds of double numbers, then the answer from this method may be Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

minimum

public double minimum()
Determine the smallest number that has been given to this Statistician.

Parameters:
- - none
Returns:
the smallest number that has been given to this Statistician since it was initialized or reinitialized.
Note:
If length() is zero, then the answer from this method is Double.NaN.

next

public void next(double number)
Give a new number to this Statistician.

Parameters:
number - the new number that is being given the this Statistician
Postcondition:
The specified number has been given to this Statistician and it will be included in any subsequent statistics.

sum

public double sum()
Determine the sum of all the numbers that have been given to this Statistician.

Parameters:
- - none
Returns:
the sum of all the number that have been given to this Statistician since it was initialized or reinitialized.
Note:
If the sum exceeds the bounds of double numbers, then the answer from this method may be Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

union

public static Statistician union(Statistician s1,
                                 Statistician s2)
Create a new Statistician that behaves as if it was given all the numbers from two other bags.

Parameters:
s1 - the first of two Statisticians
s2 - the second of two Statisticians
Precondition:
Neither s1 nor s2 is null.
Returns:
a new Statistician that acts as if it was given all the numbers from s1 and s2.
Throws:
NullPointerException. - Indicates that one of the arguments is null.