CMPT 126 - Harbour Centre - Fall 2006
Home  
Assigned Readings  
Examples  
Labs  
Assignments  
References  
Gradebook  
 
  For this assigment, you will create a simple statistics program.

The Stats

Here are the statistical values you will have to calculate. In the formulae, xi indicates the data values, and n the number of data values.

Mean

The mean is the arithmetic average:

mean = (x1 + ... + xn) / n

Variance

The variance is a measure of how spread-out the values in the data set are:

var = (x12 +...+xn2) /n - mean2

Standard Deviation

The standard deviation is another measure of the spread of the data set. It is the square root of the variance.

Histogram

A histogram is a simple graph that summarizes how the data is distributed. The range that the data covers (from the smallest to largest element) is divided into equal intervals. The number of data points in each interval is plotted.

As you can see below, the format of the histogram you have to produce here is quite simple.

The Program

Create Java class Stats in a file Stats.java .

There will be two parts to the program that the user can see: (1) enter the data, and (2) ask for various summary data.

The data will be entered one value per line. The values should be stored with the double type. There will be at most 1000 values entered; you program shouldn't accept more than 1000 values. The user will enter -1000 to indicate the end of the input. (The -1000 isn't part of the data set.)

Once the data has been entered, the user should be given a menu with four choices:

  1. Mean
  2. Variance and Standard Deviation
  3. Histogram
  4. Exit

The first three choices should display the corresponding summary data. The last should quit the program.

Histogram Format

The range of the histogram will be between the smallest and largest value in the data set. There will be 10 bars displayed, each with an equal part of the range. For example, if the smallest value is 0.0 and the largest is 10.0, the bars will represent the ranges [0.0, 1.0], (1.0, 2.0], (2.0, 3.0], ... , (9.0, 10.0].

The bars will be displayed horizontally, with the first bar (eg. 0.0 - 1.0) at the top, and the last (eg. 9.0 - 10.0) at the bottom. Each data value in the range will be represented by a *. For example, the histogram might look like this:

**
*********
********************
************************************
*****************************************
****************************************
**********************
*****************
*********
***

If the ranges are the same as the example above, there are two values in the range [0.0, 1.0], nine in the range (1.0, 2.0], and so on.

Sample Run

Sample runs have been put on separate pages: sample run 1, sample run 2.

Notes

  • All of your assignments in this class will have some marks allocated for style. This will include easy to understand and modify code. In particular, you should use comments where appropriate, use good variable names, split your code into methods/functions logically, and indent consistantly.
  • Do you know the difference between System.out.print, and System.out.println? Find out; it could make some things easier to do.
  • The Math module contains many mathematical functions, including a square root function.
  • The java.utils.Arrays module contains a function to sort an array.

When you're done, create a ZIP file containing all of the files you created for this assignment (probably just Stats.java) and submit it with the submission server before midnight on September 29th.