public class Statistician
extends java.lang.Object
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 and Description |
|---|
Statistician()
Initialize a new Statistician.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public Statistician()
public void addAll(Statistician addend)
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.java.lang.NullPointerException - Indicates that addend is null.public void clear()
public boolean equals(java.lang.Object obj)
Statistician to another object for equality.equals in class java.lang.Objectobj - an object with which this Statistician will be comparedtrue 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.public int length()
Integer.MAX_VALUE numbers, will
cause failure with an arithmetic overflow.public double maximum()
length() is zero, then the answer from this method
is Double.NaN.public double mean()
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.public double minimum()
length() is zero, then the answer from this method
is Double.NaN.public void next(double number)
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.public double sum()
Double.POSITIVE_INFINITY or
Double.NEGATIVE_INFINITY.public static Statistician union(Statistician s1, Statistician s2)
s1 - the first of two Statisticianss2 - the second of two Statisticians
Precondition:
Neither s1 nor s2 is null.java.lang.NullPointerException - Indicates that one of the arguments is null.