Java Programming 8th Edition Joyce Farrell Solutions Manualinstant download
Java Programming 8th Edition Joyce Farrell Solutions Manualinstant download
https://testbankfan.com/product/java-programming-8th-edition-
joyce-farrell-solutions-manual/
We believe these products will be a great fit for you. Click
the link to download now, or visit testbankfan.com
to discover even more!
https://testbankfan.com/product/java-programming-8th-edition-
joyce-farrell-test-bank/
https://testbankfan.com/product/java-programming-9th-edition-
joyce-farrell-solutions-manual/
https://testbankfan.com/product/java-programming-7th-edition-
joyce-farrell-solutions-manual/
https://testbankfan.com/product/prealgebra-and-introductory-
algebra-4th-edition-bittinger-test-bank/
Essentials of Federal Taxation 2016 Edition 7th Edition
Spilker Test Bank
https://testbankfan.com/product/essentials-of-federal-
taxation-2016-edition-7th-edition-spilker-test-bank/
https://testbankfan.com/product/human-anatomy-8th-edition-
martini-test-bank/
https://testbankfan.com/product/introduction-to-research-in-
education-9th-edition-ary-test-bank/
https://testbankfan.com/product/principles-of-macroeconomics-
sixth-canadian-edition-canadian-6th-edition-mankiw-solutions-
manual/
https://testbankfan.com/product/beckers-world-of-the-cell-9th-
edition-hardin-solutions-manual/
Essential Cosmic Perspective 7th Edition Bennett Test
Bank
https://testbankfan.com/product/essential-cosmic-perspective-7th-
edition-bennett-test-bank/
Java Programming, Eighth Edition 8-1
Chapter 8
Arrays
A Guide to this Instructor’s Manual:
We have designed this Instructor’s Manual to supplement and enhance your teaching
experience through classroom activities and a cohesive chapter summary.
This document is organized chronologically, using the same headings that you see in the
textbook. Under the headings you will find: lecture notes that summarize the section, Teaching
Tips, Class Discussion Topics, and Additional Projects and Resources. Pay special attention to
teaching tips and activities geared towards quizzing your students and enhancing their critical
thinking skills.
In addition to this Instructor’s Manual, our Instructor’s Resources also contain PowerPoint
Presentations, Test Banks, and other supplements to aid in your teaching experience.
At a Glance
• Objectives
• Teaching Tips
• Quick Quizzes
• Additional Projects
• Additional Resources
• Key Terms
Java Programming, Eighth Edition 8-2
Lecture Notes
Overview
Chapter 8 introduces the concept of arrays. An array is a list of elements of the same
data type. Students will learn to create arrays of primitive data types and objects. They
will work with arrays by searching, sorting, and passing them to methods.
Objectives
• Declare arrays
• Initialize an array
• Use variable subscripts with an array
• Declare and use arrays of objects
• Search an array and use parallel arrays
• Pass arrays to and return arrays from methods
Teaching Tips
Declaring Arrays
1. Introduce the concept of an array, which is a named list of data items with the same
data type. Discuss the programming situations in which an array is useful. Have the
students consider the code and the question posed on page 394.
If time permits, ask students to write a program with several related elements of
Teaching the same type, such as test scores. Once they have created a program with several
Tip scalar variables, ask how they might expand this program to several hundred
elements. This exercise will make the need for arrays very clear.
2. Describe the syntax for declaring an array. Arrays are indicated using square brackets:
double [] salesFigures;. Discuss naming strategies for arrays.
3. Explain that declaring an array does not reserve memory space for the array elements.
The process of reserving memory space is called creating the array. The new operator is
used to create an array: salesFigures = new double[20];.
Teaching An array can be declared and created in the same statement: double[]
Tip salesFigures = new double[20];.
Java Programming, Eighth Edition 8-3
4. Introduce the terms subscript and element. Define the boundaries of the array, and
explain what happens when a subscript is out of bounds. Be sure to emphasize that
arrays are zero-based. Discuss the impact this has on the first and last indexes
(subscripts) in an array.
6. Discuss the variety of methods to declare an array size shown on pages 396-397.
You Do It
1. Students should follow the steps in the book on pages 397–399 to create a Java
application that declares and initializes an array.
Initializing an Array
1. Explain how to initialize an array by assigning values to individual array elements or to
the entire array using curly brackets.
3. The {} contains the initialization list of values. Note that when the entire array is
initialized using {}, there is no need to specify the size of the array.
Teaching
When populating the array, remember that arrays start at index 0.
Tip
You Do It
1. Students should follow the steps in the book on page 401 to initialize the array of
doubles created earlier in the chapter.
Java Programming, Eighth Edition 8-4
Teaching
Remind students of the benefit of using constants over literals.
Tip
2. Explain that arrays have a length field that holds the number of elements in the array.
3. Using the code on page 402 and page 403, point out the effectiveness of combining
for loops with arrays.
4. Define the enhanced for loop, also known as the foreach loop. Compare the
traditional loop with the foreach loop using the code on page 404.
5. Write an array application during your lecture. Use both the normal for loop and the
new enhanced for loop.
Note that the enhanced for loop cannot be used in every programming situation.
Teaching
Several situations in which it is not usable are listed at the bottom of the
Tip
following page: http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html.
1. Discuss situations where you may not need all parts of an array. The code in Figure 8-4
codes a scenario where any number of quiz scores, up to 10, can be entered and
averaged.
2. Create an array in class that does not use every part of an array. An excellent example is
monthDays, which holds the number of days in each month of the year. Start with
subscript 1 instead of 0.
You Do It
1. Students should follow the steps in the book on page 406 to create a Java application
that uses a loop to access array elements.
Java Programming, Eighth Edition 8-5
2. Emphasize the need to explicitly call the constructor for each element in the array.
4. Reuse one of the classes from your earlier lectures as an array of objects. Be sure to
instantiate the values and use several of the methods.
1. Explain that you can use the enhanced for loop to cycle through an array of objects. It
eliminates the need to use a limiting value, and eliminates the need for a subscript
following each element.
Teaching Using the enhanced for loop to access array elements is often easier for new
Tip programmers to understand than the traditional for loop and subscripts.
2. During your lecture, create an array named monthNames that holds the names of the
months.
3. During your lecture, print out the abbreviations of the months using a for loop and the
substring() method of the String class.
You Do It
1. Students should follow the steps in the book on pages 409–414 to create a Java class
containing an array of Strings. This class is then used to create an array of
BowlingTeam objects.
Java Programming, Eighth Edition 8-6
Quick Quiz 1
1. True or False: You declare an array variable in the same way you declare any simple
variable, but you insert a pair of curly brackets after the type.
Answer: False
2. A(n) ____ is an integer contained within square brackets that indicates one of an array’s
variables, or elements.
Answer: subscript
3. How would you set the value of the first element in the someNums array to 42?
Answer: someNums[0] = 42;
4. The ____ loop allows you to cycle through an array without specifying the starting and
ending points for the loop control variable.
Answer: enhanced for
The search algorithm described in the text is the linear search method. Point out
Teaching
that this is the slowest search to implement, but the easiest to code. Other
Tip
methods exist and will be discussed in the next chapter.
1. Define the term parallel array as two or more arrays that store logically related
elements at corresponding indexes. Figure 8-9 shows a program that uses parallel
arrays. Figure 8-11 shows a loop with an early exit. A while loop, covered later in the
chapter, can be used in place of this if structure.
2. Point out that the monthName and monthDays arrays created during your lecture are
parallel arrays.
Teaching An alternative to using parallel arrays is to create an object that encapsulates the
Tip logically related data, and create an array holding elements of that type.
Java Programming, Eighth Edition 8-7
1. Define a range match. Explain how to search an array for a range match. This
technique is illustrated in Figure 8-13.
2. During your lecture, calculate the letter grade corresponding to a percentage using a
range match.
You Do It
1. Students should follow the steps in the book on pages 421–422 to create a Java
application that searches an array of BowlingTeam objects.
Teaching Stress the importance of understanding that primitive types are passed by value
Tip and any changes made within a method will not be seen in the calling method.
2. Review the program listing in Figure 8-18. In this program, an array is passed to a
method. Since an array is a reference type and not a primitive type, it is passed by
reference, not by value. This means that the method has the ability to alter original
values in array elements.
3. During your lecture, create a method that accepts an array for a parameter.
1. Review the program listing in Figure 8-20, which illustrates the syntax for returning an
array from a method.
You Do It
1. Students should follow the steps in the book on pages 427–428 to create a Java
application that passes an array to a method.
Don’t Do It
1. Review this section, discussing each point with your class.
Quick Quiz 2
1. A(n) ____ array is one with the same number of elements as another and for which the
values in corresponding elements are related.
Answer: parallel
2. True or False: Searching an array for an exact match is not always practical.
Answer: True
3. Arrays, like all nonprimitive objects, are ____ types; this means that the object actually
holds a memory address where the values are stored, and the receiving method gets a
copy of the array’s actual memory address.
Answer: reference
2. Is it possible to store elements with different data types in the same array? Explain why
or why not.
Additional Projects
1. An alternative to parallel arrays is to create an object that encapsulates the logically
related data and create an array holding elements of that type. Take the program
example in Figure 8-9 and modify it to get rid of the parallel arrays and use an array of
objects instead.
2. Create a program that prompts the user for an integer number and searches for it within
an array of 10 elements. What is the average number of comparisons required to find an
element in the array?
Java Programming, Eighth Edition 8-9
Hints:
• Your program should print the number of comparisons required to find the
number or determine that the number does not exist.
• Try finding the first and last number stored in the array.
• Run your program several times before computing the average.
Additional Resources
1. Details about working with arrays from developer.com:
www.developer.com/java/other/article.php/1143571
Key Terms
Array: a named list of data items that all have the same type.
Element: one variable or object in an array.
Enhanced for loop: allows you to cycle through an array without specifying the
starting and ending points for the loop control variable.
foreach loop: an enhanced for loop.
Index: another name for a subscript.
Initialization list: comma-separated values enclosed within curly braces that initialize
the elements in an array.
length field: contains the number of elements in an array.
Out of bounds: the error returned whenever an array is accessed using a subscript
either below 0 or above the largest subscript value.
Parallel array: one with the same number of elements as another and for which the
values in corresponding elements are related.
Passed by reference: when a value is passed to a method, the address is passed to the
method.
Passed by value: when a variable is passed to a method, a copy is made in the receiving
method.
Populating an array: providing values for all of the elements in an array.
Property: an object’s instance variable or field.
Range match: the process of comparing a value to the endpoints of numerical ranges to
find a category in which the value belongs.
Reference types: the object actually holds a memory address where the values are
stored.
Java Programming, Eighth Edition 8-10
III.
IV.
I.
II.
In the latter part of his life, Comte drew out precisely the features
of what he henceforth called the new Great Being. Although we
were not here to undertake to write an account of positive religion,
we must nevertheless, in a few words, indicate the form which this
supreme idea ended by assuming in Comte’s mind.
Firstly, humanity is not conceived simply as the sum of all the
individuals or human groups present, past and future. For all men
are necessarily born children of humanity; but all do not become her
servants. Many remain in the condition of parasites. All those who
are not or were not “sufficiently assimilable,”362 all those who were
only a burden to our species, do not form a part of the Great Being.
A selection takes place among men. Some finally enter into
humanity never to leave it; others leave it never to return. The
selection takes place according to the life they have preferred. Those
who have lived in the purely biological sense of the word, that is to
say, those in whom the higher faculties have been made to serve the
organic function, those whom with brutal energy Comte calls
“producteurs de fumier,”363 will only have been part of humanity in a
transitory manner. Death for them, as for their anatomical system,
will be an end without further appeal. Those in whom the “sublime
inversion” has been accomplished, or at least those who have made
an effort to subordinate the organic to the higher functions, those
finally who have worked for a pre-eminently human end: to make
the intellect predominate over the inclinations, and altruism over
egoism; those having lived for humanity will always live in her.
human end: to make the intellect predominate over the inclinations,
and altruism over egoism; those having lived for humanity will
always live in her.
As the conduct of each one can only be finally judged after his
death, humanity is essentially made up of the dead and “the
admission of the living within her will hardly ever be more than
provisional.”364 Each generation, while it lives, furnishes the
indispensable physiological substratum for the exercise of the
superior human functions. But this privilege which momentarily
distinguishes it from the others, soon slips away from it, as it slipped
away from the preceding ones, and from the men of which they
were composed; they alone who are worthy of it are incorporated
into humanity. Moreover, they are only incorporated in it by their
noblest elements. Death causes them to pass through a
“purification.”
This theory allows Comte to attain at the same time two results,
which he considers equally desirable. In the first place, the religious
idea of humanity remains in perfect accordance with the idea given
of it by biology and sociology. Humanity conceived as the Great
Being, is a kind of hypostasis of the functions by which man tends to
become distinguished from the animal. It is the progressive
realisation through time, of the intellectual and moral potentialities
contained in human nature: it is also its ideal impersonation. In this
last sense, it becomes an object of love and adoration. Thus, the
positivist religion naturally leads to a “commemoration” of great
men, the benefactors of humanity. Here we have one of the ideas
which were defined very early in Comte’s mind.
On the other hand, the desire for immortality is very strong in the
heart of man. On principle Comte recognised at any rate a
provisional value in all that arises spontaneously from human nature.
In science he saw a prolongation of “public reason,” in systematic
morality a development of spontaneous morality. He was thus led to
take into account the almost irresistible tendency which impels man
to desire to triumph over death.365 This tendency, up to the present
time, has satisfied itself by means of illusions. But beliefs of this kind
have become incompatible with the progress of our mental
evolution. Moreover, the social efficacy of hopes and fears
concerning the future life has been much exaggerated. As a matter
of fact, says Comte (and the science of religions bears him out on
this point), the tendency to desire, and consequently to accept the
idea of an ultimate survival, existed for a long time before it was
made use of to support religious beliefs or to preserve public order.
Here, again, positive philosophy does not deny, does not destroy: it
transforms. To the chimerical and vulgar notion of objective
immortality, it substitutes the notion, which is alone acceptable, of
subjective immortality. The same doctrine which takes from us the
consolations so dear to past generations, gives us an adequate
compensation, by allowing each one to hope that he may be united
to the Great Being.