Chapter 7 Lab Arrays Lab Objectives: Data Mean - The Arithmetic Average of The Scores
Chapter 7 Lab Arrays Lab Objectives: Data Mean - The Arithmetic Average of The Scores
Arrays
Lab Objectives
Be able to declare and instantiate arrays
Be able to fill an array using a loop
Be able to access and process data in an array
Be able to write a sorting method
Be able to use an array of objects
Introduction
Everyone is familiar with a list. We make shopping lists, to-do lists, assignment lists,
birthday lists, etc. Notice that though there may be many items on the list, we call the list
by one name. That is the idea of the array, one name for a list of related items. In this lab,
we will work with lists in the form of an array.
It will start out simple with a list of numbers. We will learn how to process the contents
of an array. We will also explore sorting algorithms, using the selection sort. We will
then move onto more complicated arrays, arrays that contain objects.
Average
-data [ ] :int
-mean: double
+Average( ):
+calculateMean( ): void
+toString( ): String
+selectionSort( ): void
This class will allow a user to enter 5 scores into an array. It will then rearrange the data
in descending order and calculate the mean for the data set.
Attributes:
data[]— the array which will contain the scores
mean — the arithmetic average of the scores
Methods:
Average — the constructor. It will allocate memory for the array. Use a for
loop to repeatedly display a prompt for the user which should indicate that user
/**
Constructor
@param title A reference to a String object
containing the song's title.
@param artist A reference to a String object
containing the song's artist.
*/
/**
The toString method
@return A String object containing the name
of the song and the artist.
*/
/**
This program creates a list of songs for a CD
by reading from a file.
*/
System.out.println("Contents of Classics:");
for (int i = 0; i < cd.length; i++)
{
// ADD LINES FOR TASK #3 HERE
// Print the contents of the array to the console
}
}
}