PDF Starting Out with Java From Control Structures through Objects 5th Edition Tony Gaddis Solutions Manual download
PDF Starting Out with Java From Control Structures through Objects 5th Edition Tony Gaddis Solutions Manual download
com
https://testbankdeal.com/product/starting-out-with-java-
from-control-structures-through-objects-5th-edition-tony-
gaddis-solutions-manual/
OR CLICK HERE
DOWNLOAD NOW
https://testbankdeal.com/product/starting-out-with-java-from-control-
structures-through-objects-5th-edition-tony-gaddis-test-bank/
testbankdeal.com
https://testbankdeal.com/product/starting-out-with-java-from-control-
structures-through-objects-7th-edition-gaddis-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/starting-out-with-java-from-control-
structures-through-objects-6th-edition-gaddis-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/mis-7th-edition-bidgoli-test-bank/
testbankdeal.com
Microeconomics 12th Edition Arnold Test Bank
https://testbankdeal.com/product/microeconomics-12th-edition-arnold-
test-bank/
testbankdeal.com
https://testbankdeal.com/product/learning-
sage-50-accounting-2016-a-modular-approach-1st-edition-freedman-
solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/mastering-social-psychology-1st-
edition-baron-test-bank/
testbankdeal.com
https://testbankdeal.com/product/contemporary-financial-
intermediation-3rd-edition-greenbaum-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/international-financial-management-
canadian-perspectives-2nd-edition-eun-test-bank/
testbankdeal.com
E Commerce 2016 Business Technology Society 12th Edition
Laudon Solutions Manual
https://testbankdeal.com/product/e-commerce-2016-business-technology-
society-12th-edition-laudon-solutions-manual/
testbankdeal.com
Chapter 7 Lab
Arrays
Lab Objectives
Be able to declare and instantiate arrays
Be able to fill an array using a for 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 should
34
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
enter score number 1, score number 2, etc. Note: The computer starts counting
with 0, but people start counting with 1, and your prompt should account for this.
For example, when the user enters score number 1, it will be stored in indexed
variable 0. The constructor will then call the selectionSort and the
calculateMean methods.
calculateMean – this is a method that uses a for loop to access each score in
the array and add it to a running total. The total divided by the number of scores
(use the length of the array), and the result is stored into mean.
toString— returns a String containing data in descending order and the mean.
selectionSort—this method uses the selection sort algorithm to rearrange
the data set from highest to lowest.
2. Compile, debug, and run the program. It should output the data set from highest
to lowest and the mean. Compare the computer’s output to your hand calculation
using a calculator. If they are not the same, do not continue until you correct your
code.
35
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Code Listing 7.1 (Song.java)
/*This program represents a song*/
public class Song
{
/**The title of the song*/
private String title;
/**The artist who sings the song*/
private String artist;
/**constructor
@param title The title of the song
@param artist The artist who sings the song*/
public Song(String title, String artist)
{
this.title = title;
this.artist = artist;
}
36
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
artist = input.readLine();
// fill the array by creating a new song with
// the title and artist and storing it in the
// appropriate position in the array
}
System.out.println("Contents of Classics:");
for (int i = 0; i < cd.length; i++)
{
//print the contents of the array to the console
}
}
}
37
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Another Random Document on
Scribd Without Any Related Topics
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back