Question
Statistician Class You will implement and test a Statistician class as described in the documenation of http://www.cs.colorado.edu/~main/docs/edu/colorado/homework/Statistician.html . Please make sure to add comments and
Statistician Class
You will implement and test a Statistician class as described in the documenation of http://www.cs.colorado.edu/~main/docs/edu/colorado/homework/Statistician.html . Please make sure to add comments and explanations explaining the code.
Class Statistician
java.lang.Object
edu.colorado.homework.Statistician
public class Statistician extends java.lang.Object
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
Constructors
Constructor and Description Statistician() Initialize a new Statistician.
Method Summary
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. |
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
Statistician
public Statistician()
Initialize a new Statistician. 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. 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.
Returns:
the count of how many numbers have been given to this Statistician since it was initialized or reinitialized. Note: Giving a Statistician more thanInteger.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.
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.
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 orDouble.NEGATIVE_INFINITY.
minimum
public double minimum()
Determine the smallest number that has been given to this Statistician.
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.
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:
java.lang.NullPointerException - Indicates that one of the arguments is null.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started