COMP 14-090 Summer I 2000
Assignment 6: An Array Calculator
Assigned: Thursday, June 15
Due: Tuesday, June 20
Worth: 80 points
Description
This assignment will use the skills of reading from a text file, taking
command-line arguments, and manipulating an array of doubles. The text
file to read from will be given as a command-line argument. Open
the text file and read in the first number, which will be an integer.
This number will tell you how many doubles are in the file. Read
in each double into a single array. Print out the name of the file
you read, the contents of the array, and the results of the following operations:
-
find the minimum value
-
find the maximum value
-
compute the sum
-
compute the average
-
compute the running total
-
compute the square (not square root) of each number
-
compute the variance - (average of the squares - square of the average)
-
compute the standard deviation - (the square root of the variance)
Use DecimalFormat to round the results to one decimal place. You only need
one class for this program, but each operation listed above should be in a
separate method. Don't print anything to the user inside these
methods -- only print to the user inside main (or inside another method that
only does output).
Hints
-
For computing the square of each number and the running total, you'll have
to create new arrays to hold the results.
-
Running total -- for example, if the array was 1, 2, 3, the running total
would be an array that contained 1, 3, 6.
-
For computing the standard deviation, use Math.sqrt(), which takes a double
as a parameter and returns its square root.
-
Use methods that you've already written instead of re-writing code.
For example, calculating the average could call the calculate sum method
to return the sum before dividing. The variance method can also make
much use of previously written methods.
-
We'll cover reading text files in class today (Thursday), so there will
be an example in the notes and on the course web page.
-
For an example of handling command-line arguments, look at Listing 6.6
(NameTag.java) on page 281 of your textbook.
-
Since the ArrayCalc class holds no state, all of the methods can be declared
as static. This also means that you don't have to instantiate an
object of the class, just use the methods by their name and parameters
(example: sum = calcSum (numbers); ).
What to Turn In
-
A printout of your Java source code.
-
A disk with your Java source code (ArrayCalc.java) and bytecode (ArrayCalc.class).
-
An image of the output window. Make sure you see "==> End of job" before
you capture the image. (You may include the output window image in the
same document as your memo instead of turning in a separate printout of
the output window.)
-
A memo describing the problem and your solution of it. Include any problems
you encountered or comments you may have about the assignment. Also, include
an estimate of the total amount of time you spent working on this assignment.
Steps to Follow
-
Follow the instructions in Getting Started with Visual
J++ under "Creating a New Project."
Use Assignment6 as your project name.
-
Follow the instructions under "Adding a
New Class." Name your class ArrayCalc.
-
Write in English the algorithm that you would use to complete this assignment.
-
Take each part one at a time and convert that to Java.
-
To run the program with a command line argument, select Assignment6
Properties... from the Project menu. The window that pops
up is below. Pick Custom then type the command line arguments
(put complete filename in quotation marks) after ArrayCalc in the
Arguments
box. Make sure that the Program box says
JView.exe
and not WJView.exe
Notes
-
Don't forget to comment your program! If there are no comments, you will
lose at least 20% of the points.
-
Don't forget to virus check and label your disk according to the instructions
in Turning in Assignments on Disk.
-
Don't forget to sign the pledge on the printout of your source code.
- Extra Credit will be given for printing out the sorted
array (using either selection sort or insertion sort).
10 points ascending order (lowest to highest)
15 points descending order (highest to lowest)
20 points both
The following output window is just an example. You don't have to use
the same formatting. To get black text on a
white background, I pasted the captured image into the Paint program
and inverted the colors.
The input file for the following example contained:
7
99.8
67.8
88.4
76.2
101.4
89.6
94.3

Michele Clark
clark@cs.unc.edu