Java Programming 7th Edition Joyce Farrell Test Bank - Download Today For Unlimited Reading
Java Programming 7th Edition Joyce Farrell Test Bank - Download Today For Unlimited Reading
_____ Follow the link below to get your download now _____
https://testbankdeal.com/product/java-programming-7th-
edition-joyce-farrell-test-bank/
https://testbankdeal.com/product/java-programming-7th-edition-joyce-
farrell-solutions-manual/
https://testbankdeal.com/product/java-programming-9th-edition-joyce-
farrell-test-bank/
https://testbankdeal.com/product/java-programming-8th-edition-joyce-
farrell-test-bank/
https://testbankdeal.com/product/physical-examination-and-health-
assessment-5th-edition-jarvis-test-bank/
Introduction to Emergency Management 1st Edition Lindell
Solutions Manual
https://testbankdeal.com/product/introduction-to-emergency-
management-1st-edition-lindell-solutions-manual/
https://testbankdeal.com/product/fundamentals-of-advanced-
accounting-5th-edition-hoyle-solutions-manual/
https://testbankdeal.com/product/mktg-9-9th-edition-lamb-test-bank/
https://testbankdeal.com/product/fundamentals-of-corporate-
finance-8th-edition-brealey-test-bank/
https://testbankdeal.com/product/cognitive-psychology-connecting-mind-
research-and-everyday-experience-3rd-edition-goldstein-solutions-
manual/
Statistics for Business and Economics Canadia 5th Edition
Lind Test Bank
https://testbankdeal.com/product/statistics-for-business-and-
economics-canadia-5th-edition-lind-test-bank/
Chapter 8: Arrays
TRUE/FALSE
1. You can declare an array variable by placing curly brackets after the array name.
2. When an application contains an array and you want to use every element of the array in some task, it
is common to perform loops that vary the loop control variable from 0 to one less than the size of the
array.
3. When you want to determine whether a variable holds one of many valid values, one option is to use a
do…while loop to compare the variable to a series of valid values.
4. When using parallel arrays, if one array has many possible matches, it is most efficient to place the
less common items first so that they are matched right away.
5. Many programmers feel that breaking out of a for loop early disrupts the loop flow and makes the
code harder to understand.
8. When array elements are passed by value, a copy of the value is made and used within the receiving
method.
9. Since an array name is a reference, you are able to use the = operator for assigning and the == operator
for comparisons.
10. When returning an array reference, square brackets are included with the return type in the method
header.
1. After you create an array variable, you still need to ____ memory space.
a. create c. reserve
b. organize d. dump
ANS: C PTS: 1 REF: 399
2. In Java, the size of an array ____ declared immediately following the array name.
a. can be c. is never
b. is always d. should be
ANS: C PTS: 1 REF: 399
3. Languages such as Visual Basic, BASIC, and COBOL use ____ to refer to individual array elements.
a. ( ) c. { }
b. [ ] d. < >
ANS: A PTS: 1 REF: 399
4. A(n) ____ is an integer contained within square brackets that indicates one of an array’s variables.
a. postscript c. variable header
b. subscript d. indicator
ANS: B PTS: 1 REF: 399
5. When you declare an array name, no computer memory address is assigned to it. Instead, the array
variable name has the special value ____, or Unicode value ‘\u0000’.
a. empty c. false
b. null d. zero
ANS: B PTS: 1 REF: 404
6. In Java, boolean array elements automatically are assigned the value ____.
a. null c. true
b. ‘\u0000’ d. false
ANS: D PTS: 1 REF: 404
7. When you create an array of objects, each reference is assigned the value ____.
a. null c. true
b. ‘\u0000’ d. false
ANS: A PTS: 1 REF: 404
8. You use a ____ following the closing brace of an array initialization list.
a. . c. :
b. ; d. ,
ANS: B PTS: 1 REF: 404
9. Providing values for all the elements in an array is called ____ the array.
a. populating c. filling
b. declaring d. irrigating
ANS: A PTS: 1 REF: 404
10. When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed
to a method, the value is passed.
a. array c. element
b. dummy d. primitive
ANS: D PTS: 1 REF: 427
11. The length ____ contains the number of elements in the array.
a. box c. area
b. field d. block
ANS: B PTS: 1 REF: 407
12. A(n) ____ loop allows you to cycle through an array without specifying the starting and ending points
for the loop control variable.
a. do…while c. enhanced for
b. inner d. enhanced while
ANS: C PTS: 1 REF: 407
13. If a class has only a default constructor, you must call the constructor using the keyword ____ for each
declared array element.
a. default c. first
b. new d. object
ANS: B PTS: 1 REF: 411
14. Comparing a variable to a list of values in an array is a process called ____ an array.
a. validating c. checking
b. using d. searching
ANS: D PTS: 1 REF: 418
15. A ____ array is one with the same number of elements as another, and for which the values in
corresponding elements are related.
a. cloned c. property
b. parallel d. two-dimensional
ANS: B PTS: 1 REF: 419
16. When you initialize parallel arrays, it is convenient to use ____ so that the values that correspond to
each other visually align on the screen or printed page.
a. tabs c. spacing
b. indentation d. dashes
ANS: C PTS: 1 REF: 420
17. When you perform a ____, you compare a value to the endpoints of numerical ranges to find the
category in which a value belongs.
a. range match c. reference
b. sort d. search
ANS: A PTS: 1 REF: 422
18. It is a good programming practice to ensure that a subscript to an array does not fall below zero,
causing a(n) ____.
a. array dump c. conundrum
b. runtime error d. compiling error
ANS: B PTS: 1 REF: 423
19. Individual array elements are ____ by value when a copy of the value is made and used within the
receiving method.
a. sorted c. received
b. passed d. stored
ANS: B PTS: 1 REF: 426-427
21. When a method returns an array reference, you include ____ with the return type in the method header.
a. { } c. < >
b. ( ) d. [ ]
ANS: D PTS: 1 REF: 429
22. Which of the following println statements will display the last myScores element in an array of
10?
a. System.out.println(vals[0]); c. System.out.println(vals[9]);
b. System.out.println(vals[1]); d. System.out.println(vals[10]);
ANS: C PTS: 1 REF: 400
23. Which of the following statements correctly declares and creates an array to hold five double scores
values?
a. integer[] scores = new double[5] c. double[] = new scores[5]
b. double[] scores = new integer[5] d. double[] scores = new double[5]
ANS: D PTS: 1 REF: 400
24. Which of the following statements correctly initializes an array with an initialization list?
a. int[] nums = {2, 4, 8}; c. int nums = [2, 4, 8];
b. int[] nums = (2, 4, 8); d. int nums() = int{2, 4, 8}
ANS: A PTS: 1 REF: 404
COMPLETION
1. A(n) ____________________ is a named list of data items that all have the same type.
ANS: array
PTS: 1 REF: 398
2. When you declare or access an array, you can use any expression to represent the size, as long as the
expression is a(n) ____________________.
ANS: integer
3. When you declare int[] someNums = new int[10];, each element of someNums has a value
of ____________________ because someNums is a numeric array.
ANS:
0
zero
4. An instance variable or object field is also called a(n) ____________________ of the object.
ANS: property
ANS: value
MATCHING
SHORT ANSWER
1. Describe a situation in which storing just one value at a time in memory does not meet your needs.
ANS:
At times you might encounter situations in which storing just one value at a time in memory does not
meet your needs. For example, a sales manager who supervises 20 employees might want to determine
whether each employee has produced sales above or below the average amount. When you enter the
first employee’s sales value into an application, you can’t determine whether it is above or below
average because you don’t know the average until you have all 20 values. Unfortunately, if you
attempt to assign 20 sales values to the same variable, when you assign the value for the second
employee, it replaces the value for the first employee.
ANS:
A subscript is an integer contained within square brackets that indicates one of an array’s variables, or
elements. In Java, any array’s elements are numbered beginning with 0, so you can legally use any
subscript from 0 to 19 when working with an array that has 20 elements.
3. What does an array’s name represent and what value does it hold when declared?
ANS:
Array names represent computer memory addresses; that is, array names contain references, as do all
Java objects. When you declare an array name, no computer memory address is assigned to it. Instead,
the array variable name has the special value null, or Unicode value ‘\u0000’. When you declare
int[] someNums;, the variable someNums has a value of null.
4. When working with arrays, why is it beneficial to use a loop with a declared symbolic constant equal
to the size of the array?
ANS:
It is convenient to declare a symbolic constant equal to the size of the array and use the symbolic
constant as a limiting value in every loop that processes the array. That way, if the array size changes
in the future, you need to modify only the value stored in the symbolic constant, and you do not need
to search for and modify the limiting value in every loop that processes the array.
ANS:
When an application contains an array and you want to use every element of the array in some task, it
is common to perform loops that vary the loop control variable from 0 to one less than the size of the
array. For example, if you get input values for the elements in the array, alter every value in the array,
sum all the values in the array, or display every element in the array, you need to perform a loop that
executes the same number of times as there are elements.
6. How would you use a method that belongs to an object that is part of the array? Use an example and
demonstrate with Java code.
ANS:
To use a method that belongs to an object that is part of an array, you insert the appropriate subscript
notation after the array name and before the dot that precedes the method name. For example, to print
data for seven Employees stored in the emp array, you can write the following:
ANS:
When you initialize parallel arrays, it is convenient to use spacing so that the values that correspond to
each other visually align on the screen or printed page.
8. How would a programmer perform a range match when writing an application that takes into
consideration different discount rates for customers? Give an example.
ANS:
Create two corresponding arrays and perform a range match, in which you compare a value to the
endpoints of numerical ranges to find the category in which a value belongs. For example, one array
can hold the five discount rates, and the other array can hold five discount range limits. If you only use
the first figure in each range, you can create an array that holds five low limits:
Then, starting at the last discountRangeLimit array element, for any numOfItems greater than
or equal to discountRangeLimit[4], the appropriate discount is discount[4]. In other
words, for any numOrdered less than discountRangeLimit[4], you should decrement the
subscript and look in a lower range.
PTS: 1 REF: 422
9. What is different about passing an array to a method rather than passing a primitive type to a method?
ANS:
The outcome is quite different when you pass an array (that is, pass its name) to a method. Arrays, like
all nonprimitive objects, are reference 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. Therefore, the receiving method has access to, and the ability to alter, the original values in
the array elements in the calling method.
ANS:
You can use the enhanced for loop to cycle through an array of objects. For example, to display data
for seven Employees stored in the emp array, you can write the following:
In this loop, worker is a local variable that represents each element of emp in turn. Using the
enhanced for loop eliminates the need to use a limiting value for the loop and eliminates the need for
a subscript following each element.
11. When populating an array with an initialization list, you do not need to use the new keyword or
provide an array size. Explain why this is the case.
ANS:
When you populate an array upon creation by providing an initialization list, you do not
give the array a size because the size is assigned based on the number of values you place in the
initializing list. Also, when you initialize an array, you do not need to use the keyword new. New
memory is assigned based on the length of the list of provided values.
12. Why is the length field a good option when writing a loop that manipulates an array? What
programming error is common when attempting to use length as an array method?
ANS:
You can use a field (instance variable) that is automatically assigned a value for every array you
create. The length field contains the number of elements in the array. Later, if you modify the size
of the array and recompile the program, the value in the length field of the array changes
appropriately. When you work with array elements, it is always better to use a symbolic constant or the
length field when writing a loop that manipulates an array.
13. While you can provide any legal identifier you want for an array, conventional rules are typically
followed. List and describe the naming conventions for naming arrays.
ANS:
Java programmers conventionally name arrays by following the same rules they use for variables:
Array names start with a lowercase letter.
Use uppercase letters to begin subsequent words.
The above code creates an array named sixNumbers. Describe how array sizes are determined when
using an initialization list and how memory is assigned.
ANS:
When you populate an array upon creation by providing an initialization list, you do not give the array
a size—the size is assigned based on the number of values you place in the initializing list. For
example, the sixNumbers array in the sample code has a size of 4. Also, when you initialize an
array, you do not need to use the keyword new because new memory is assigned based on the length
of the list of provided values. In Java, you cannot directly initialize part of an array. For example, you
cannot create an array of 10 elements and initialize only five; you must initialize either every element
or none of them.
Create a loop that will add 2 to every array element. Use a symbolic constant named PLUSTWO and
use the length field in the loop that will contain the number of elements in the array.
ANS:
for(counter = 0; counter < increaseValues.length; ++counter)
increaseValues[counter] += PLUSTWO;
CASE
Once the above code is compiled and executed, an error message is generated. Explain the error
message that will result and explain the reason for the error.
ANS:
An out-of-bounds error is generated when the code is compiled and executed. The last executable line
in the code is an output statement that attempts to display a costs value using a subscript that is
beyond the range of the array: System.out.println(costs[3]). The program will run
successfully when the subscript used with the array is 0, 1, or 2. However, when the subscript reaches
3, the ArrayIndexOutOfBoundsException error is generated. The message indicates that the
subscript is out of bounds and that the offending index is 3.
Using the above statement, what will be the value of countyNames[0], countyNames[1], and
countyNames[2]?
ANS:
countyNames[0] will hold the value “Clark”
countyNames[1] will hold the value “Delaware”
countyNames[2] will hold the value “Madison”
3. Write the statement to create an array named studentScores that will store five integer value
student scores. Initialize the array using an initialization list with the values 70, 85, 92, 67, and 76.
ANS:
int[] studentScores = {70, 85, 92, 67, 76};
4. Using just one statement, declare and create an array that will reserve memory locations for 10
scores values that are type double.
ANS:
double[] scores = new double[10];
5. Write the statement to declare an array of integers that will hold studentScores.
ANS:
int[] studentScores;
6. double[] studentScores;
double studentScores[];
Are both of the above statements valid for declaring an array variable? Why or why not?
ANS:
You declare an array variable in the same way you declare any simple variable, but you insert a pair of
square brackets after the type. To declare an array of double values to hold studentScores, you
can write the following:
double[] studentScores;
In Java, you can also declare an array variable by placing the square brackets after the array name, as
in double studentScores[];. This format is familiar to C and C++ programmers, but the
preferred format among Java programmers is to place the brackets following the variable type and
before the variable name.
ANS:
countyNames[0].length() will have a value of 5
countyNames[1].length() will have a value of 8
countyNames[2].length() will have a value of 7
Using the above code, write the statement that will return the array name.
ANS:
return studentScores;
9. Write the statement to declare an array variable named studentScores with type double. Write a
second statement to create an array of 10 objects.
ANS:
double[] studentScores;
studentScores = new double [10];
Write a println statement to display the last element of the studentScores array.
ANS:
System.out.println(studentScores[2]);
There was another who saw this tableau and knew its meaning.
Judas Maccabæus had entered the court at the moment, and, as his
custom was, without heralding. He paused by the entrance. He took
in at a glance all the scene,—and saw also some things which were
not outwardly acted. Noting that he had been unobserved, he went
silently out, and with bowed head tramped along the Street of
David, through the Cheesemakers' Street, and out to the Hill of
Ophel, where he sat long upon a ruined coping of the Gymnasium,
and gazed down the Valley of Kedron, and over the slopes of the
mountains of the Wilderness. But, as Meph, who had followed him,
said to a comrade, "Judas looked, but he saw nothing."
Deborah had led her visitors into a room adjacent to the court. Here
Agathocles narrated that part of Sirach's story which the old
servant's sudden infirmity, many days before, had cut short.
"Ctesiphon! Well did Sirach give him praise. It was Ctesiphon who
dared to plead for the Jews before the raging Ptolemy. It was he
who, when the elephants were about to trample the Jews in the
arena, went in among them, and dragged Nahum away.
"Nahum's daughter, Sara, was at the time concealed at my house. I
had loved my neighbor's child alway, though we were of different
races. After King Ptolemy's rage had abated—thanks chiefly to
Ctesiphon's influence with the King—the Jews often came to my
house when they visited their kinsman Nahum. Thus I often saw
your father, Shattuck. He was a princely fellow; of wondrous
gentility; and withal as much shrewdness as any of his race. My
money I left with him, sure of its proper usury. He soon won the
affection of Sara, and they were betrothed and wedded according to
their nation's custom. The coming of Sara's child, and the death of
Shattuck, her husband, were near together. The attempt upon little
Gershom's life led me to take Sara and her babe to my home. To
better protect her from unknown enemies I brought her to
Macedonia. There she became my wife. She took the name of Agnes
for better concealment of her identity. Her child Gershom she
consented to call Dion. But this is no place to open the memories of
a broken heart."
He rose to go away. Deborah besought him to remain.
"No, no!" he replied, and he passed into the street, leaving Dion to
piece together the story as he might; or, if he cared, to begin his
own life-story anew.
An hour later a horn sounded from the parapet of the house of
Elkiah; for such was the custom of the Jews, that the passers-by
might know that death was within the walls. They washed the body
of Sirach, trimmed the hair and nails, and wrapped him in new white
linen. They laid the form upon a bier. A rabbi came, and spoke words
of eulogy over a faithful servant. Women entered the court, with
dishevelled hair, and, to the accompaniment of flutes, chanted a
weird mourning dirge, and cast dust of ashes toward the body.
About sunset a little procession emerged from the house. Ephraim
would have taken the position of chief mourner, as befitted his
condition at a fellow-servant's burial; but Agathocles displaced him,
and walked nearest to the bier. Dion went by his side.
Thus they buried Gideon ben Sirach on the slope of the vale of
Jehoshaphat, in the family tomb of the house of Shattuck—for so
Dion, now Gershom ben Shattuck, ordered it to be.
XLIX
THE HIDDEN HAND
Judas left little time for any to dispute his decision. His tremendous
energy was imparted to every man about him. Priests were loaded
with questions regarding their ancient customs, which absorbed their
study day and night, for Judas would immediately reorganize their
order according to the Aaronic ideal. Such artisans as were still to be
found among the people, builders in stone, carvers of wood, and
women skilled in needlework, were given their part in the problem of
the renovation of the Temple. The city walls were to be
strengthened, new citadels built in the surrounding villages, cordons
of forts placed around the entire land, the army to be reorganized
for more systematic defence, and new campaigns planned to
effectually awe the surrounding tribesmen.
Every day saw the mark of the master-hand of their leader. The
rubbish heaps outside the gates were ornamented with the
shattered pieces of pagan statuary. The sacred courts on Mount
Moriah were purged of every stain of the heathen Abomination. A
new altar rose on the site of the ancient one. Its stones were
untouched by chisel, only laid together symmetrically, as befitted a
memorial to Him who created all things without the help of human
hands. The stones of the ancient altar, which had been desecrated
by the foul offerings of the Greeks, were laid away until the great
Messiah should come.
The crowning act of Greek pollution had taken place three years
before, on the twenty-fifth day of the month Chisleu, which
corresponds with the Roman month of December. Judas appointed
the same date for the Feast of Dedication, which has been annually
repeated ever since throughout the Jewish world.
For eight days the streets of the city and all the highways leading to
its gates from valley and hill were thronged with processions bearing
palm branches, and shouting the old Hallel psalms. In many groups
were those who had not touched hands for years; men who had
come out of hiding-places where they had taken covert from the
incessant persecution. Some came laden with their goods, making
willing offerings of coins and jewels to swell the fund for the glorious
work.
At each nightfall every house gleamed like a constellation with
crowded lights in doorway and window, and on parapet and dome.
The Temple plaza blazed with great fires which sent beams of hope
far over the Judean hills, and by the glare in the sky proclaimed the
triumph of Israel to the camps of the enemy beyond the borders.
One house outshone all other private dwellings on the third night of
the Feast of Dedication. It stood near to the western gate, close by
the Tower of David, with the city's breadth separating it from the
Temple. The fires on the roof of this house saluted as with waving
hands of flame the blazing glory of the Temple Mount. This was the
old mansion of Shattuck, for years deserted, but now reoccupied by
its new-found inheritor.
Between this house and that of Elkiah the streets were densely
crowded on that third night. At the middle hour a cry rent the air:
"She comes! She comes!"
Close back against the houses the people were massed. There was
no need of official command, for the populace was moved by a
common gladness and reverence.
There was but one instance of what would have seemed to a
stranger a breach of decorum. Down the street came Meph waving
his crutch like the baton of a marshal, and shouting:
"Make way! Make way for the Daughter of Jerusalem! Way for the
bride of Ben Shattuck!"
No one rebuked the lad, for the story of his part in bringing about
the regeneration of the popular Greek into a Jew was well known.
"Bless the boy!" was the only comment heard as his heels conducted
both himself and the pageant that followed.
The procession was more artistically heralded by bands of players on
flute and tabor, succeeded by those leading the multitude in the
ancient marriage song of the people.
Amid a hundred torches was seen the gigantic form of Judas
together with his brethren. For this hour at least all traces of
solemnity and care were banished from his face, as he led the
"friends of the bridegroom," who, according to the time-honored
custom, were conducting the bride to the house of her husband.
As Deborah appeared surrounded by her maidens the cries, "Long
live Judas Maccabæus!" were quickly changed.
"Joy! joy to the daughter of Elkiah! Long live Deborah, the Daughter
of Jerusalem!" rang from a thousand lips.
The happy crowd hurried along as if impelled by their own huzzas,
until the bride disappeared within the portal of the house of
Shattuck.
An hour later Judas sat alone in his chamber in the palace on Sion.
The stars as they floated by looked through the high window, but
did not disturb the soul which at that hour was moving through
depths as profound as theirs. The gray dawn alone aroused him—in
which there was a poetic propriety; for since the day-spring
summons all nature to activity, why should it not awaken the
tremendous forces of this great heart for its work in resurrecting a
nation?
Judas reached out his hand and struck the bronze gong—the same
that Apollonius had rung three years before when he was
vanquished by the spirit of Deborah in this same hall.
"Call the Captains!"
His chief officers came with evidence of hasty toilet—for celerity
never waited upon formality in the councils of Judas. His sentences,
as he addressed them, were laconic, as if he assumed that his
hearers had listened at his brain and already knew his thoughts.
"Friends, I learn that the men of Edom are moving from their camps
on the south. The tribesmen of the Jordan and beyond are preparing
to strike us. Tyre and Sidon are enrolling their trained bands. Every
man, then, in readiness by the turn of the moon!"
With a wave of his hand he dismissed them.
The result of this order belongs to history, which tells how the
invincible men of Judas, beginning on the south, swung to east, then
from east to north, then from north to west, and then from west to
south again—the swing of the mighty Hammer of Israel—crushing a
hostile tribe at every stroke, until Judah lay quiet within all its
desolate borders.
No sword gleamed brighter in those days than that of Gershom ben
Shattuck, and no foeman gave more desperate battle than Nadan,
son of Yusef, Sheikh of Jericho.
HENRY CHUNG
Korean Commissioner
to America and Europe
The Case of Korea
A Collection of Evidence on the Japanese
Domination of Korea, and on the Development of
the Korean Independence Movement. Illustrated.
$3.00
"A masterly indictment of the Japanese
Government before the bar of modern civilization. The
author has presented what he claims to be facts, and
gives the evidence and the authorities. It is an amazing
array, causing the reader to rub his eyes and wonder."—
Boston Transcript.
JOSEPH HOCKING
Author of "The Passion for Life"
Prodigal Daughters
$1.75
Another tale which, like "The Passion for Life,"
will hold the reader spell-bound until the last
page is reached. It is a frank, up-to-date story
of what Henry van Dyke calls "this generation
of butterflies". A powerful piece of writing in
which the famous novelist graphically describes the
struggle against the flood of new morals and ethics and
dress of the younger generation.
DAVID HOWARTH
The Valley of Gold
A Tale of the Saskatchewan. Illustrated
$1.75
A rip-roaring story of the great North-West country by a
brand new writer. A "RALPH CONNORESQUE" story replete
with incident—tests of strength, keen rivalries between
farm-crews and wheat farmers, and hot-blood
developments arising therefrom. There is, of course, a fine
love story intertwining the rougher happenings, together
with the other elements which go to make a big, gripping
story.
CHARLES M. SHELDON
In His Steps Today
What Would Jesus Do Regarding the
Problems of Today?
$1.25
"Read with eager interest. It will awaken
many fellow-Christians to see new fields in
which to apply all the Christianity there is."—
Prof. Graham Taylor in Chicago Commons.
WILLIAM S. WALKLEY
Three Golden Days
Tan-Bark Tales—Illustrated.
$1.25
With marked fidelity the author reproduces the
atmosphere of the Big Tent with its tan-bark ring,
lumbering elephants, prancing horses, and mirth-
provoking clown.
MARGARET E. SANGSTER
The Island of Faith
A Story of New York's East Side.
$1.25
"For it is a girl's story and one that can safely be put into
the hands of awakening womanhood, since it will not only
give them the romance girls crave, but will show them
what one girl's fine, high visions did for humanity."—
Examiner.
testbankdeal.com