P6: Fun with Arrays
COMP 14-091 Summer Session I 2000
Assigned: Friday, June 16
Due: Friday, June 23, at the
beginning
of class!
Description
This assignment gives you a chance to work with arrays and hopefully to
see how useful they are. You should write a program that creates an array
of 10 doubles (floating point numbers) and then asks the user to enter
the 10 doubles (if you can't figure out how to make doubles work, then
you can use int instead, but you will lose points for this). After reading
the 10 values in from the user, you need to print out the contents of the
array and then calculate the following things:
-
the minimum value in the array
-
the maximum value in the array
-
the sum of the elements of the array
-
the average of the elements of the array
-
the average of the squares of the elements of the array (square each element
in the array and then average these squared values)
-
the variance of the array = average of the squares minus the square of
the average (so #5 - the square of #4)
-
the standard deviation = the square root of the variance (so the square
root of #6)
Each of these calculations should be in a separate method! To get you started,
I have written the method that calculates the minimum value of the array.
If you can't get the extra methods to work, then you can do all the calculations
in main, but you will lose points for doing that!
Hints
-
Keep in mind that the methods you write can call each other (this will
be VERY useful to you)
-
You will end up with a .java file with 8 methods in it (the main method,
the 1 I wrote and the 6 you have to write)
-
Your methods can go above or below the main method. The order doesn't really
matter. BUT, main should be either first or last.
Don't forget to check the program grading criteria
to see all the normal stuff your program should do.
Extra Credit
For this assignment you can do the following to get extra credit. However,
you can only receive a maximum of 100 points for this assignment. These
are also all or nothing - no partial extra credit.
-
5 pts - Ask the user how many doubles they want to type in and use
that instead of 10 (everything else must still work correctly no matter
what number the user enters)
-
10 pts for the first, 15 pts for both - Print out the array in sorted
order from minimum to maximum or maximum to minimum (Your sort code MUST
be in it's own method)
Steps to Follow
This time you will only have one class in your project. It should be a
ClassMain class when you create it. You should call it ArrayComputation.java.
Click on this link to get my framework version of it that has the first
method written for you already.
Don't forget all the comments and the honor code pledge that should
go at the top of each class in your program!
What to turn in
(don't forget to keep a copy for yourself!):
-
a disk with your Java code (the file ArrayComputation.java) on it
in a directory called P6. It's ok if this directory contains the
other files that Microsoft Visual J++ puts in the project directory.
-
Please print out a copy of your code to hand in to me - it will help
me grade your assignments faster!
-
any notes/comments you might have about your solution to the assignment,
trouble you had, etc. This should go in a file called "readme.doc" in the
directory
P6
-
Ok, here's exactly what your should be on your disk (you will lose 10 pts
if you don't follow this exactly!):
-
A:\P6\ArrayComputation.java your code for this assignment
-
A:\P6\readme.doc
anything you would like me to read while I'm grading your assignment (optional)
Notes
-
Check out the general Program Grading Criteria
-
Take a look at the Ten Steps to make your
life easier.
-
DON'T forget to comment your program! You will lose points if you don't
comment the program! (the grading is 50% for correctness and 50% for
commenting)
Note: this is only an example. Your work does not need to match the
example word for word.
Here is an example run with the extra credit working: