05-Week.docx

advertisement

Week 05 assignment

You may start with the code from last week’s program. Your program will

1.

Display your name, as usual, in a GUI window.

2.

Use Chooser to allow the user to select a file.

3.

Open the file, and read all the lines in the file, counting them.

4.

Then your program will close the input file.

5.

Now allocate an array of double large enough to store one double for each line you read.

6.

Your program should then open the input file again. Assume that each line of the file contains a number in a format that Double.parseDouble can handle. Use Double.parseDouble to convert each line of the file into a number, and store those numbers into the array you declared.

7.

Pass the array into a method named calculateMean, which will return the mean (regular old average – the sum divided by the number) .

8.

Pass the array into a method named calculateStandardDeviation, which will return the sample standard deviation.

9.

Pass the array into a method named calculateMaximum, which will return the maximum value in the array.

10.

Pass the array into a method named calculateMinimum, which will return the minimum value in the array.

11.

Display the mean, standard deviation, maximum, and minimum using a GUI window.

Formulas: mean =

𝑥̅ =

𝑛 𝑖=1

𝑥

𝑖

𝑛

standard deviation =

𝑛 𝑖=1

(𝑥

𝑖

𝑛−1

−𝑥̅)

2

In words:

To calculate the mean, add up all the x’s, and divide the sum by the number of x’s.

To calculate the standard deviation, for each x, calculate how far it is away from the mean ( 𝑥 𝑖

− 𝑥̅ ), then square each distance. Then add up all the squares Divide that sum by one less than the

number of x’s. Then take the square root of that quotient.

A test data set named 05-Week-Sample-Data.txt appears in the Assignments folder of the class website.

You may make a copy of it and use it to test your program.

For the test data:

Mean:

Std Dev:

Min:

Max:

81.64375

13.91211056

49.17

100

Turn in your .java program (it should be named Week5.java) in the week 5 drop box. To get full credit, turn it in by 12:00 noon on Sunday. To get up to 90%, turn it in by midnight Monday night.

Download