Java Programming 7th Edition Joyce Farrell Test Bankdownload
Java Programming 7th Edition Joyce Farrell Test Bankdownload
Bank download
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.
Visit https://testbankdead.com
now to explore a rich
collection of testbank,
solution manual and enjoy
exciting offers!
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]);
As she sat at the small table, her senses dull to everything, she did
not hear a knock at her door; nor was she aware that a man had
come in and was there, before her, waiting. A sudden leap of her
heart, and a flash of consciousness made her raise her eyes. She
thought she must be feverish, in a delirium! She would have cried
out, but something within her, that overpowered her, muffled her
voice.
"Nacha!" he said.
"Is this true? It is not a dream? Not a dream?"
They were face to face, but they could not speak. No words could
express what shone in Monsalvat's eyes, and echoed in Nacha's
breathless weeping. The room seemed to fill with memories of the
distant past, scenes fraught with sorrow, and ancient longings,
taking on a strange, mysterious life, like an old temple that has
heard the prayers of centuries.
Nacha's tears were for what had been, and what ought to have
been; for what she had not wanted to be, and what the world had
forced her to become. Monsalvat sat at her side, caressing her
hands; but he saw facing him the two men he had been in his
lifetime, and he demanded an account of them for what his life had
been, looking into their very souls, cursing them; and before Nacha
passed the different women who had dwelt in her body, the bad
woman, and the good, the victim and the weakling.
And in that dim light, they understood one another, these two
suffering human beings. The light in the heart of each shone out to
the other. Their heads drew close together. Without knowing it,
without seeking it, they kissed gently, like children of one mother.
CHAPTER XVII
Monsalvat that very afternoon had taken lodgings in the house in
order to be near Nacha. As Torres signed it, he read the receipt of
the special delivery letter; and he hurried to the Messenger Service
Bureau and there learned Nacha's address. When he reached the
building where she lived he noticed a sign announcing a furnished
room to let in this tenement which was an old family dwelling, now
rented out to numerous lodgers. Monsalvat took the room on the top
floor facing the street. Thus, it happened that when he appeared in
Nacha's quarters he was already a tenant in the same house.
Torres' efforts to find out what had become of Monsalvat were all
unsuccessful. He even wrote to Nacha, who replied that she had not
seen him nor had any news of him. These falsehoods did not much
trouble her conscience. She wanted to keep Monsalvat near her,
have him for herself alone; and she was fearful of his friends, of his
associates at the ministry, of everything which threatened to
interrupt her possession of him. When, in the afternoon, she came
home from work, she could scarcely breathe with the anxiety and
the fear of no longer finding him there.
But the emotion she felt was to all appearances purely fraternal.
Suffering had spiritualized it. The first kiss had been the last. Nacha
knew how little the physical aspect of love meant. She could not
offer her lover something of as little price as her body. To Monsalvat
she would give her heart and soul and whatever good there was in
her; her tenderness, as immeasurable as space, and her suffering,
as deep as the sea. Nor did he desire her. Nacha was no longer a
mere woman to him; she had become a symbol, tremendously
significant, of all women who pay the penalty she was paying, of
those victims rejected by society—daughters of the mire and of
human misery; and she was his sister as well. If at times he desired
Nacha, the desire was fleeting, a passing sentiment. He knew that it
was this sentiment which had drawn him towards her; and in this
fact he saw a proof of the wisdom of instinct, of nature's
fundamental soundness; for desire had, in moments of vacillation
and uneasiness of conscience, led him to the right road. Now he was
no longer a man of the world, nor a distinguished lawyer, nor
anything else that he had been. As far as the world was concerned,
he was a ruined man. But in his own eyes he had saved himself,
found a purpose for his life; the purpose to give everything he had
to others, and to suffer for them. What did all the rest matter if, in
this course of conduct, he found what he recognized as the "Good"
he craved?
And so time passed. Nacha went to the shop in the morning, and
returned at night. Monsalvat went out only to go to the Ministry, and
to offer relief to those in great need. When he came back from the
office he gathered the children in the house together and taught
them to read; and his evenings were for Nacha, for long waking
dreams—a book in his hands, and silence keeping watch over them
like a faithful dog. His evenings were for that idealized love which
Nacha too now understood.
But one evening Nacha told him of the doubts that troubled her.
Why sacrifice one's life, and tranquillity, and happiness, for others?
With so much wretchedness in the world, what could one man's slow
and small accomplishment matter? And why give one's whole soul to
something that offered no visible reward?
"Nacha," he replied, "to sacrifice ourselves for others is a duty. It is
the only reason for our living. If we all accepted this principle, life
would be inconceivably beautiful. And what other principle makes
our lives consistent with our opinions and our ideals—granted we
have opinions and ideals? It is an obligation we owe to those from
whom we have taken their share of happiness. There are not many
who pay this debt, not many who comply with this law. People not
only resist the law of love implicit in sacrifice, but they will to be
selfish, and bad. But doesn't that make it all the more our duty,
Nacha, to do what we can? We must win forgiveness for the wrongs
we do our brothers, for the guilt of society in which we all share."
He stopped, and looked dreamily before him, as though he saw
some luminous object in the distance. Then, after a moment of
silence, he added:
"The work of one individual has tremendous value as an example.
Good work is not lost. It arouses other souls; and each one of these
will waken others, who, but for them, would continue to sleep. So,
little by little, daylight will come; injustice will cease; and poverty will
be a word."
Monsalvat was at work on two plays which Nacha helped him to
copy. They proved to be somewhat incoherent compositions, full of
anguish, and love, and pity. They excited keen interest among the
theatrical managers to whom he submitted them but no one cared
to produce them. Some one of the readers who examined them
called the plays "anti-social"; and they were generally considered
dangerous to established order. In truth, they contained too much
human sympathy: but it may well be that justice, or even simple
honesty, is a serious menace to society!
One Sunday afternoon Julieta came to call on Nacha. She was no
longer the smiling Julieta of old. Bad luck had been haunting her
footsteps of late; and for the last few weeks she had known what it
was to go hungry. While she was telling Nacha her troubles
Monsalvat came in. Julieta did not know him, and stopped short.
"It is my friend," said Nacha. "He can help you. Go on!"
Julieta, reassured as much by a glance at Monsalvat as by Nacha's
words, told how her small savings had all been spent to help Sara
who had suddenly developed a horrible disease.
"I thought I could earn more if I had to," said Julieta, "but I haven't
been able to. I've had to give up my room at Lavalle Street; and
they are going to put me out of the lodging house where I have
been staying, because my rent isn't paid. I can't go out on the
street! But I'm discouraged. What can I do? I had hoped to get away
from this life somehow; and now it seems as though I would have to
go deeper into it than ever before—and after seeing what has
happened to poor Sara! Oh, I can't bear to think of it!"
"Everything is going to come out right for you," Monsalvat said to
her gently. "What little I have is yours. Don't thank me. No, I shall
be angry if you do. It isn't mine after all. No one is the owner of
money. It's stupid to think so! Don't lose heart. I'm going to take
care of all your troubles. No, it isn't only for you I am doing this. It's
for myself, you see."
Monsalvat had received his salary that afternoon. He had just paid
his rent; and he gave all that remained to Julieta, who let herself be
persuaded finally to accept it. Then he left the girls alone.
As he went out of the door, he found, leaning against the wall
opposite, his legs crossed, an ill-favored individual who looked at
him with an impudent and sinister smile. Nacha could not endure
this cross-eyed and thoroughly unprepossessing loafer, who, it was
rumored, was a police spy. His small, close-set eyes, low forehead,
crushed-in nose and vicious expression all suggested the jail bird;
and Nacha could never see him without having a ghastly vision of all
the crimes a man is capable of; nor was she alone in fearing him.
But she learned on a certain occasion that he knew her past life, and
the discovery kept her awake many nights. As the days passed
without her hearing anything more from him, she put aside the
worst of her fears. The man watched Monsalvat closely and even
followed him on the street.
When Monsalvat returned to Nacha's room, Julieta had gone. Nacha
was depressed and this he naturally attributed to Julieta's trouble.
But Nacha was tormented by various concerns of her own, of which
she never spoke. One was her wretched poverty. To eke out her
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
testbankdeal.com