CSC 132 Fall 2000

Homework Assignment 1

Due: midnight September 6, 2000

30 points

"Stats is stats"

NOTE: I have upgraded this assignment from a Lab assignment to a Homework assignment and postponed the due date appropriately. At 10 a.m. September 1, I copied submitted solutions onto my hard drive. Those solutions will be considered for bonus credit. I encourage even those who already submitted solutions to continue working on this assignment to perfect it, and resubmit before the revised deadline.

This assignment is a slight variation on Chapter 2 Programming Assignments 2 and 3.

You are to design and implement a class called Statistic. A client should be able to use this this class to do a number of things: create a named Statistic object, collect a "double" numeric value, retrieve the smallest or largest value collected so far, retrieve the sum, mean (average) or standard deviation of the values collected so far, retrieve a count of the number of values collected, retrieve the name of the object, and combine two Statistic objects into a third which represents their composite.

Prototypes for these methods are given here. The purpose of each should be obvious based on its name and the narrative above.

public Statistic(String name) 		// constructor
public double getSmallest() 		// smallest value collected so far
public double getLargest() 		// largest value collected so far
public double getSum() 			// sum of values collected so far
public int getLength() 			// number of values collected so far
public double getMean() 		// average of values collected so far
public double getStandardDeviation()	// standard deviation of values collected
public String getName() 		// name of object (see constructor)
public void collect(double value) 	// collect a value
public static Statistic combine(Statistic first, Statistic second)

Details

  1. You need to decide what instance variables will be needed to implement these methods, and add them to the class definition. They should of course be private.
  2. Your Statistic class definition must be stored in file Statistic.java. The Statistic class will NOT include a "main" as it is not intended to be used as a stand-along application. No other classes should be defined in this file. Any driver classes defined for testing your code should be put into a different file. The CSC 132 download folder on eccentric contains a driver program called StatisticDriver.java you can use to partially exercise your code. It contains only one test, so you'll need to extend it to fully exercise your code.
  3. Do NOT store every collected value, such as in an array. Everything, including standard deviation, can be implemented without storing individual collected values.
  4. Given a collection X of values x1, x2, ..., xn, the mean is defined as (Σ xi)/n.
  5. The standard deviation of a collection of values is defined as the square root of the variance of that collection. Variance is defined as the average squared deviation from the mean. The formula to calculate variance can be reduced to: E(X2) - (E(X)) 2, where E is "expected value" (or mean) and X represents the collection of values. E(X2) = (Σ xi2)/n and E(X) = (Σ xi)/n, where xi are individual values collected and n is the number of values collected. For example, if you collected the values 1.0, 2.0,3.0,4.0,5.0, then E(X2) = 11.0, (E(X)) 2 = 9.0, the variance is 11.0-9.0 = 2, and the standard deviation is square root of 2 = 1.414.
  6. For the "combine" method, the idea is to create a new Statistic object whose variables would have the same values as if everything collected for the original two objects were instead collected by the new one. So if the original two objects had collected 5 and 7 values respectively, the combined object will have 12 for this variable. If the original two objects had smallest value of -6.5 and 12.3 respectively, the combined object would have -6.5 (the smaller of the two). By implementing this as a static method of the Statistic class, the "combine" method has access to the private variables of both original objects.
  7. Due to inaccuracies in computation with floating point numbers, operations on the Java "double" data type do not throw exceptions (for such conditions as zero divide); they instead produce a special constant result called Double.NaN. See textbook page 713, paragraph "Special Values". In the situation where no values have been collected yet, getLength and getSum should return 0.0, but the others (getSmallest, getLargest, getMean, getStandardDeviation) should return Double.NaN.
  8. In addition to all this, document your code using comments in such a way that the "javadoc" utility can be used to produce a nice web page describing it. See textbook page 759 for an example of comments that should go at the top of the class definition. See page 757 for an example of comments that should go at the top of each method. Note that your methods (other than "combine") will not have preconditions or exceptions, so all you need are the @param and @return.
  9. When finished, submit your work by copying Statistic.java into your folder in the CSC 132 upload folder on eccentric. This folder is named after your Gold domain ID.

Maximum point assignments are: 5 points documentation, 5 points design and code structure, 20 points correct and reliable results. Documentation includes use of comments (see detail #8), use of self-documenting identifier names, and judicious use of white space (such as indentation) to enhance readability. Design and code structure includes appropriate use of object-oriented design and programming features (including testing preconditions). "Correct and reliable results" are based on my acceptability tests and the ability of your program to meet the specifications of the assignment correctly. Your programs will be tested using the JDK 1.3 "javac", "java" and "javadoc" commands. Note that Forte as installed in the labs uses JDK 1.3.


[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]


Last reviewed: 1 September 2000

Peter Sanderson ( PeteSanderson@smsu.edu )