Note: This lab is graded and will be worth 2 points toward your overall grade. If you do not finish this in the first week, you will be given time at the beginning of next week's lab to demo it for your TA.
As we discussed in lecture, arrays can be very useful data structures. We already discussed how to load items into an array and how to search an array for an item. In this lab you will implement a number of other useful operations that can be done on arrays. You will then write a simple main program to utilize your methods. For help with this lab, see course notes for Lectures 11-12 and handouts ex11.java and ex12a.java
Lab Exercise
You are to write the following 4 methods:
public static double max(double []
data) // return the maximum value in the
//
array.
public static double min(double []
data) // return the minimum value in the
//
array
public static double sum(double []
data) // sum the items in the array
//
and return the result
public static double ave(double
[] data) // call sum to get the sum
//
and then return the average
Once you have completed the methods above, write a simple main program that does the following:
1) Asks the user how many items will be entered
2) Creates an array of double of the correct size
3) Prompts the user and reads in the values
4) Calculates and prints out the max, min, sum and average using the methods
above
Grading and Submission
Demonstrate that your program works correctly to your TA by running it for him/her.
Answer the question asked by your TA.
This lab is worth 2 grade points, distributed as shown below.
Since this lab is worth 2 points for your final grade, the points received will be divided by 10.0 to determine your final score.
Notes and Hints
The methods that you must implement are fairly intuitive. See ex11.java and ex12a.java for help with setting things up and with the I/O.