Java Programming 8th Edition Joyce Farrell Test Bank pdf download
Java Programming 8th Edition Joyce Farrell Test Bank pdf download
Bank download
https://testbankfan.com/product/java-programming-8th-edition-
joyce-farrell-test-bank/
https://testbankfan.com/product/java-programming-8th-edition-joyce-
farrell-solutions-manual/
https://testbankfan.com/product/java-programming-7th-edition-joyce-
farrell-test-bank/
https://testbankfan.com/product/java-programming-9th-edition-joyce-
farrell-test-bank/
https://testbankfan.com/product/intro-stats-4th-edition-veaux-test-
bank/
Data Structures And Algorithm Analysis In C++ 4th Edition
Weiss Solutions Manual
https://testbankfan.com/product/data-structures-and-algorithm-
analysis-in-c-4th-edition-weiss-solutions-manual/
https://testbankfan.com/product/price-theory-and-applications-9th-
edition-landsburg-solutions-manual/
https://testbankfan.com/product/math-in-our-world-3rd-edition-sobecki-
solutions-manual/
https://testbankfan.com/product/small-business-an-entrepreneurs-plan-
enhanced-canadian-7th-edition-knowles-test-bank/
https://testbankfan.com/product/java-foundations-3rd-edition-john-
lewis-test-bank/
MR 2 2nd Edition Brown Test Bank
https://testbankfan.com/product/mr-2-2nd-edition-brown-test-bank/
Name: Class: Date:
1. You can declare an array variable by placing curly brackets after the array name.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 394
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.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 402
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.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 414
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.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 417
5. Many programmers feel that breaking out of a for loop early disrupts the loop flow and makes the code harder to
understand.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 418
6. To initialize an array, you use an initialization list of values separated by commas and enclosed within curly braces.
a. True
b. False
ANSWER: True
Cengage Learning Testing, Powered by Cognero Page 1
Name: Class: Date:
POINTS: 1
REFERENCES: 400
8. When array elements are passed by value, a copy of the value is made and used within the receiving method.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 423-424
9. Since an array name is a reference, you are able to use the = operator for assigning and the == operator for
comparisons.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 424
10. When returning an array reference, square brackets are included with the return type in the method header.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 426
Multiple Choice
11. After you create an array variable, you still need to ____ memory space.
a. create b. organize
c. reserve d. dump
ANSWER: c
POINTS: 1
REFERENCES: 395
12. When you declare or access an array, you can use any expression to represent the size, as long as the expression is
_____.
a. a variable b. enclosed in brackets
c. an integer d. a list
ANSWER: c
POINTS: 1
REFERENCES: 396
13. Languages such as Visual Basic, BASIC, and COBOL use ____ to refer to individual array elements.
a. ( ) b. [ ]
c. { } d. < >
ANSWER: a
POINTS: 1
REFERENCES: 395
14. A(n) ____ is an integer contained within square brackets that indicates one of an array’s variables.
a. postscript b. subscript
c. variable header d. indicator
ANSWER: b
POINTS: 1
REFERENCES: 395
15. 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 b. null
c. false d. zero
ANSWER: b
POINTS: 1
REFERENCES: 400
16. In Java, boolean array elements automatically are assigned the value ____.
a. null b. ‘\u0000’
c. true d. false
ANSWER: d
POINTS: 1
REFERENCES: 400
17. When you create an array of objects, each reference is assigned the value ____.
a. null b. ‘\u0000’
c. true d. false
ANSWER: a
POINTS: 1
REFERENCES: 400
18. You use a ____ following the closing brace of an array initialization list.
a. . b. ;
c. : d. ,
Cengage Learning Testing, Powered by Cognero Page 3
Name: Class: Date:
ANSWER: b
POINTS: 1
REFERENCES: 400
19. Providing values for all the elements in an array is called ____ the array.
a. populating b. declaring
c. filling d. irrigating
ANSWER: a
POINTS: 1
REFERENCES: 400
20. When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the
value is passed.
a. array b. dummy
c. element d. primitive
ANSWER: d
POINTS: 1
REFERENCES: 424
21. The length ____ contains the number of elements in the array.
a. box b. field
c. area d. block
ANSWER: b
POINTS: 1
REFERENCES: 403
22. 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 b. inner
c. enhanced for d. enhanced while
ANSWER: c
POINTS: 1
REFERENCES: 403
23. If a class has only a default constructor, you must call the constructor using the keyword ____ for each declared array
element.
a. default b. new
c. first d. object
ANSWER: b
POINTS: 1
REFERENCES: 408
24. Comparing a variable to a list of values in an array is a process called ____ an array.
a. validating b. using
Cengage Learning Testing, Powered by Cognero Page 4
Name: Class: Date:
c. checking d. searching
ANSWER: d
POINTS: 1
REFERENCES: 415
25. A ____ array is one with the same number of elements as another, and for which the values in corresponding elements
are related.
a. cloned b. parallel
c. property d. two-dimensional
ANSWER: b
POINTS: 1
REFERENCES: 415
26. 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 b. indentation
c. spacing d. dashes
ANSWER: c
POINTS: 1
REFERENCES: 417
27. 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 b. sort
c. reference d. search
ANSWER: a
POINTS: 1
REFERENCES: 419
28. 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 b. runtime error
c. conundrum d. compiling error
ANSWER: b
POINTS: 1
REFERENCES: 420
29. Individual array elements are ____ by value when a copy of the value is made and used within the receiving method.
a. sorted b. passed
c. received d. stored
ANSWER: b
POINTS: 1
REFERENCES: 423-426
30. When any primitive type variable is passed to a method, the _____ is passed.
a. value b. reference
c. location d. memory
ANSWER: a
POINTS: 1
REFERENCES: 424
31. When a method returns an array reference, you include ____ with the return type in the method header.
a. { } b. ( )
c. < > d. [ ]
ANSWER: d
POINTS: 1
REFERENCES: 426
32. Which of the following println statements will display the last myScores element in an array of 10?
a. System.out.println(vals[0]); b. System.out.println(vals[1]);
c. System.out.println(vals[9]); d. System.out.println(vals[10]);
ANSWER: c
POINTS: 1
REFERENCES: 396-397
33. Which of the following statements correctly declares and creates an array to hold five double scores values?
a. integer[] scores = new double[5] b. double[] scores = new integer[5]
c. double[] = new scores[5] d. double[] scores = new double[5]
ANSWER: d
POINTS: 1
REFERENCES: 397
34. Which of the following statements correctly initializes an array with an initialization list?
a. int[] nums = {2, 4, 8}; b. int[] nums = (2, 4, 8);
c. int nums = [2, 4, 8]; d. int nums() = int{2, 4, 8}
ANSWER: a
POINTS: 1
REFERENCES: 400
Completion
36. A(n) ____________________ is a named list of data items that all have the same type.
Cengage Learning Testing, Powered by Cognero Page 6
Name: Class: Date:
ANSWER: array
POINTS: 1
REFERENCES: 394
37. When you declare or access an array, you can use any expression to represent the size, as long as the expression is a(n)
____________________.
ANSWER: integer
POINTS: 1
REFERENCES: 396
38. When you declare int[] someNums = new int[10];, each element of someNums has a value of
____________________ because someNums is an integer array.
ANSWER: 0
zero
POINTS: 1
REFERENCES: 400
39. An instance variable or object field is also called a(n) ____________________ of the object.
ANSWER: property
POINTS: 1
REFERENCES: 403
40. When any primitive type is passed to a method, the ____________________ is passed.
ANSWER: value
POINTS: 1
REFERENCES: 424
Matching
404
399
426
44. Declared in the same way you declare any simple variable
ANSWER: a
POINTS: 1
50. Describe a situation in which storing just one value at a time in memory does not meet your needs.
ANSWER: 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
Cengage Learning Testing, Powered by Cognero Page 8
Name: Class: Date:
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.
POINTS: 1
REFERENCES: 394
51. What is a subscript and how are the array’s elements numbered?
ANSWER: 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.
POINTS: 1
REFERENCES: 395
52. What does an array’s name represent and what value does it hold when declared?
ANSWER: Array names contain references, as do all Java object names. When you declare an array name using
only a data type, brackets, and a name, no memory address is assigned to it. Instead, the array variable
name has the special value null. When you declare int[] someNums;, the variable
name someNums has a value of null.
POINTS: 1
REFERENCES: 400
53. When working with arrays, why is it beneficial to use a loop with a declared constant equal to the size of the array?
ANSWER: It is convenient to declare a named constant equal to the size of the array and use it 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 named, symbolic constant, and you do not need to search for
and modify the limiting value in every loop that processes the array.
POINTS: 1
REFERENCES: 403
54. When using an array with all elements used, why would a programmer use a loop control variable from 0 to one less
than the size of the array? Give an example.
ANSWER: 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.
POINTS: 1
REFERENCES: 402
55. 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.
ANSWER: 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 display
data for seven Employees stored in the emps array, you can write the following:
+ emps[x].getSalary());
POINTS: 1
REFERENCES: 408
56. Why would you use spacing when initializing parallel arrays?
ANSWER: 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.
POINTS: 1
REFERENCES: 417
57. How would a programmer perform a range match when writing an application that takes into consideration different
discount rates for customers? Give an example.
ANSWER: 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.
POINTS: 1
REFERENCES: 419
58. What is different about passing an array to a method rather than passing a primitive type to a method?
ANSWER: Because an array name is a reference, you cannot assign another array to it using the = operator, nor can
you compare two arrays using the == operator. Additionally, when you pass an array (that is, pass its
name) to a method, the receiving method gets a copy of the array’s actual memory address. This means
that the receiving method has access to, and the ability to alter, the original values in the array elements
in the calling method.With a primitive, the method gets a copy of the variable's value, not the address of
the value, so the original value cannot be altered by the method.
POINTS: 1
REFERENCES: 424
In this loop, worker is a local variable that represents each element of emps 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.
POINTS: 1
REFERENCES: 408
60. 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.
ANSWER: 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.
POINTS: 1
REFERENCES: 400
61. 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?
ANSWER: The length field contains the number of elements in the array. 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 named constant or the length field when writing
a loop that manipulates an array.
A frequent programmer error is to attempt to use length as an array method, referring
to xxx.length(). However, length is not an array method; it is a field. An instance variable or
object field such as length is also called a property of the object.
POINTS: 1
REFERENCES: 403
62. 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.
ANSWER: 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.
Additionally, many programmers observe one of the following conventions to make it
more obvious that the name represents a group of items:
Arrays are often named using a plural noun such as salesFigures.
Arrays are often named by adding a final word that implies a group, such as salesList.
POINTS: 1
REFERENCES: 394-395
The above code creates an array named multsOfTen. Describe how array sizes are determined when using an
initialization list and how memory is assigned.
ANSWER: 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 multsOfTen array just defined has a size of 6. Also, when you initialize an array, you do not need
to use the keyword new; instead, new memory is assigned based on the length of the list of provided
Cengage Learning Testing, Powered by Cognero Page 11
Name: Class: Date:
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 either must initialize every element or none of them.
POINTS: 1
REFERENCES: 400
Create a loop that will add INCREASE to every array element. Use the length field in the loop that will contain the
number of elements in the array.
ANSWER: for(sub = 0; sub < scoreArray.length; ++sub)
scoreArray[sub] += INCREASE;
POINTS: 1
REFERENCES: 403
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.
ANSWER: 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.
POINTS: 1
REFERENCES: 399
Using the above statement, what will be the value of countyNames[0], countyNames[1], and
countyNames[2]?
ANSWER: countyNames[0] will hold the value “Clark”
countyNames[1] will hold the value “Delaware”
countyNames[2] will hold the value “Madison”
POINTS: 1
Cengage Learning Testing, Powered by Cognero Page 12
Name: Class: Date:
REFERENCES: 408-409
67. 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.
ANSWER: int[] studentScores = {70, 85, 92, 67, 76};
POINTS: 1
REFERENCES: 400
68. Using just one statement, declare and create an array that will reserve memory locations for 10 scores values that
are type double.
ANSWER: double[] scores = new double[10];
POINTS: 1
REFERENCES: 395
69. Write the statement to declare an array of integers that will hold studentScores.
ANSWER: int[] studentScores;
POINTS: 1
REFERENCES: 394
Are both of the above statements valid for declaring an array variable? Why or why not?
ANSWER: 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.
POINTS: 1
REFERENCES: 394
Using the above code, write the statement that will return the array name.
ANSWER: return studentScores;
POINTS: 1
REFERENCES: 426
73. Write the statement to declare an array variable named studentScores with type double. Write a second
statement to create an array of 10 objects of type double.
ANSWER: double[] studentScores;
studentScores = new double [10];
POINTS: 1
REFERENCES: 395
Write a println statement to display the last element of the studentScores array.
ANSWER: System.out.println(studentScores[2]);
POINTS: 1
REFERENCES: 396
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
testbankfan.com