CS 1054 Exam 2
How many comparisons are necessary to find the value 86 in the following list using a binary search? 13 25 28 30 39 43 44 58 66 70 78 81 86 88 95
4
What number is printed by the following code? int num = 20; switch (num) { case 1: num = num + 1; break; case 12: num = num + 1; num = num * 2; case 20: num = num * 2; case 25: num = num + 1; break; case 999: num = 20; break; default: num = 999; } System.out.println(num);
41
stage
A JavaFX window.
layout pane
A container that manages the visual presentation of the nodes it contains.
action event
A general type of event generated by several GUI controls.
character set
A list of characters used by a programming language.
JavaFX
A new framework for developing Java programs that use graphics and GUIs.
What would happen if there were more than 100 values in the input file?
A run-time error would occur.
ASCII
A small character set containing primarily English characters and basic symbols.
array initialization list
A technique for creating an array and assigning it some initial values.
event
A user action (often), such as clicking a button or moving the mouse.
control
A user interface element such as a button, text field, or slider.
Unicode escape sequence
A way to represent non-ASCII Unicode characters in a program.
index
An integer value that is used to access a particular element in an array.
array
An object that holds a set of values that can be accessed using a numeric index.
event handler
An object that responds to an event when it occurs.
What type of event does a check box generate when clicked?
action event
nodes
all elements in the scene
Which action causes three distinct mouse events to occur?
clicking the moues button
true or false: All JavaFX nodes except a Scene can generate mouse events.
false
Which type of mouse event is used to generate roll over effects?
mouse entered
true or false: A track pad generates mouse events.
true
scene
A container that manages the nodes in an interface.
change listener
An object that responds to the change in a value.
Swing API
An older approach to developing Java GUI programs.
Which of the following expressions represents the color white?
Color.rgb(255, 255, 255)
If the following arc is an ArcType.ROUND arc, which direction would it "point"? That is, where is the center point of the ellipse relative to the arc? new Arc(200, 200, 70, 30, 45, 90)
DOWN new Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
TRUE OR FALSE: A Polygon or Polyline can have at most 10 vertices.
FALSE
TRUE OR FALSE: A Polygon or Polyline object must contain at least two vertices.
FALSE
TRUE OR FALSE: A Polyline is a closed shape.
FALSE
TRUE OR FALSE: A toggle group is used to set the visual layout of its radio buttons.
FALSE
TRUE OR FALSE: An exception will be thrown if a radio button has not been made part of a toggle group.
FALSE
TRUE OR FALSE: Java represents a color using the CMYK color model.
FALSE
TRUE OR FALSE: Only one radio button displayed in a window can be selected at any time.
FALSE
TRUE OR FALSE: The JavaFX Image class does not currently support the PNG image format.
FALSE
TRUE OR FALSE: The body of a for loop is always executed at least once.
FALSE
TRUE OR FALSE: The control variable must be declared in the for loop header.
FALSE
TRUE OR FALSE: The expression in a switch statement can be an int or double value.
FALSE
TRUE OR FALSE: The leftmost end point of a line segment must be specified as the start point of the line.
FALSE
TRUE OR FALSE: The parameters to the Rectangle constructor represent the upper left corner and lower right corner of the rectangle.
FALSE
TRUE OR FALSE:If left unspecified, the font applied to a Text object is 12 point Lucinda Grande.
FALSE
If the following arc is an ArcType.ROUND arc, which direction would it "point"? That is, where is the center point of the ellipse relative to the arc? new Arc(170, 100, 50, 60, -20, 40)
LEFT new Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
What output is printed by the following code? String str = "Refactor Java"; int index = 0; int num = 0; while (index < str.length()) { if (str.charAt(index) == 'a') num++; index++; } System.out.println("Num: " + num);
Num: 3
Which statement is true about the following two circles? new Circle(50, 120, 50) new Circle(70, 120, 20)
One fully surrounds the other (but they don't have the same center point).
If the following arc is an ArcType.ROUND arc, which direction would it "point"? That is, where is the center point of the ellipse relative to the arc? new Arc(150, 250, 100, 150, 160, 40)
RIGHT new Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
TRUE OR FALSE: A radio button can be part of only one toggle group.
TRUE
TRUE OR FALSE: A rectangle's corners can be rounded using calls to the setArcWidth and setArcHeight methods.
TRUE
TRUE OR FALSE: A wrapper class "wraps" a primitive value as an object.
TRUE
TRUE OR FALSE: An Image object cannot be displayed directly in a scene.
TRUE
TRUE OR FALSE: An ImageView can be used to set the size at which an image is presented.
TRUE
TRUE OR FALSE: An alpha channel value of 1.0 represents a fully opaque color.
TRUE
TRUE OR FALSE: An image can be loaded into an Image object from a web page.
TRUE
TRUE OR FALSE: Objects created from the Color class are immutable.
TRUE
TRUE OR FALSE: Radio buttons work in a group to provide a set of mutually-exclusive options.
TRUE
TRUE OR FALSE: Setting a viewport does not change the underlying image.
TRUE
TRUE OR FALSE: The Text class and the Font class are part of the same package.
TRUE
TRUE OR FALSE: The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue.
TRUE
TRUE OR FALSE: The values passed to a Polygon constructor represent the vertices of the polygon.
TRUE
What does the fourth parameter in this method call represent? Color.rgb(100, 100, 200, 0.65);
The alpha channel (transparency)
Unicode
The character set Java uses to represent characters.
event-driven processing
The programming technique in which a program responds to user interface actions.
What happens when the mouse pointer is moved across a scene?
a series of mouse moved events are generated
What type of event does a Button produce when it is clicked with the mouse?
action event
true or false: A parameter to the Button constructor specifies the event handler for the button.
false
true or false: Each check box in your program must have its own event handler.
false
true or false: Selecting a check box will automatically unselect any other check boxes in its group.
false
true or false: Text color is determined by the font applied to a Text object.
false
true or false: The event handler method for a Button must be called handleButton.
false
true or false: The font applied to a Text object determines whether that text is underlined or not.
false
true or false: When creating a Text object, you specify the position on which you want the text centered.
false
Which of the following arcs is the same as this one? new Arc(200, 220, 80, 50, 40, 140)
new Arc(200, 220, 80, 50, -180, -140) new Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
Which of the following circles is largest?
new Circle(50, 50, 50) new Circle(centerX, centerY, radius)
Which of the following ellipses is also a circle?
new Ellipse(100, 200, 55, 55) new Ellipse(centerX, centerY, radiusX, radiusY)
Which of the following ellipses is thinner than it is tall?
new Ellipse(140, 100, 20, 50) new Ellipse(centerX, centerY, radiusX, radiusY)
Which of the following lines is horizontal?
new Line(25, 70, 125, 70) new Line(startX, startY, endX, endY)
Which of the following rectangles extends furthest down?
new Rectangle(50, 85, 70, 75) new Rectangle(x, y, width, height)
What Button method is called to set the event handler for the button?
setonAction
Which of the following would be most appropriate to choose with a set of check boxes?
the languages your speak
TRUE OR FALSE: Whether text is displayed in bold or italic type is a function of the font object applied to the text.
true
true or false: A Button can display text and an image at the same time.
true
true or false: A MouseEvent object can be used to obtain the location where the event occurred.
true
true or false: Arial is an example of a font family.
true
true or false: In the ButtonDemo example, the handleButton method is called each time the button is pushed.
true
true or false: You can get the currently selected button from the ToggleGroup object.
true
true or false: You can ignore the event generated when a check box is clicked.
true
What is the output of the following code? int[] list = {2, 4, 6, 8, 10}; int num = 0; for (int val : list) { num = num + val; } System.out.println(num);
30
TRUE OR FALSE: It's important to understand array processing to understand how to use an ArrayList.
FALSE
TRUE OR FALSE: The increment section of the for loop header always adds 1 to the loop control variable.
FALSE
TRUE OR FALSE: To change the algorithm for finding a minimum value into one that finds a maximum value, the condition of the for loop would change.
FALSE
What does the following for loop do? for (int num = 3; num <= 30; num += 3) System.out.println(num);
Prints the multiples of 3 between 3 and 30 (3, 6, 9, etc.)
Which of the following declares a valid Scanner object to read an input file named myData.txt?
Scanner in = new Scanner(new File("myData.txt"));
What is the element type of the adjectives array in the ArrayOfStringDemo program?
String
What is the type of the variable adjectives in the ArrayOfStringDemo program?
String[]
TRUE OR FALSE: An array that holds objects is, itself, an object.
TRU
TRUE OR FALSE: A break statement is used at the end of each case of a switch statement to keep processing from continuing into the next case.
TRUE
TRUE OR FALSE: A for loop could always be written as an equivalent while loop.
TRUE
TRUE OR FALSE: A for-each loop can be used to compute the sum of all values in an array.
TRUE
TRUE OR FALSE: A for-each loop cannot be used to print the elements in an array backwards.
TRUE
TRUE OR FALSE: A for-each loop cannot be used to set the values in an array.
TRUE
TRUE OR FALSE: A generic class operates on a generic type, which is specified when an object is created.
TRUE
TRUE OR FALSE: A switch statement can always be rewritten as a series of nested if statements.
TRUE
TRUE OR FALSE: An ArrayList cannot store primitive types such as int or double.
TRUE
TRUE OR FALSE: An ArrayList is a collection that can be processed using a for-each loop.
TRUE
TRUE OR FALSE: An array of objects is really an array of object references.
TRUE
TRUE OR FALSE: An output file should always be closed when you're done using it or data may be lost.
TRUE
TRUE OR FALSE: File I/O operations may throw checked exceptions.
TRUE
TRUE OR FALSE: Traversing an array or collection means accessing each element one at a time.
TRUE
TRUE OR FALSE: in the palindromes program, the inner loop evaluates one string to see if its a palindrome
TRUE, the outer loop allows multiple strings to be evaluated
What will happen if you try to add a String object to an ArrayList created to hold Person objects?
The compiler will issue an error message.
root node
The node that contains all other nodes in a scene.
What happens when an element is removed from an ArrayList?
The remaining elements are shifted to close the gap.
lexicographic ordering
The technique of ordering characters based on a character set.
When performing a binary search, how many comparisons are required to find a value in a list of N values, in the worst case?
log2N + 1
What string is printed by the following code if it is executed when the value of finger is 3? switch (finger) { case 1: System.out.println("Thumb"); break; case 2: System.out.println("Index finger"); break; case 3: System.out.println("Middle finger"); break; case 4: System.out.println("Ring finger"); break; case 5: System.out.println("Pinky"); break; default: System.out.println("Not a finger!"); }
middle finger
Which assignment statement is functionally equivalent to the following if statement? if (num1 > total) num1 = total; else num1 = 0;
num1 = (num1 > total) ? total : 0;
TRUE OR FALSE: Finding a minimum value requires that every element in the array be considered.
TRUE
TRUE OR FALSE: If you try to access an element outside of the valid index range for an array, an exception will be thrown.
TRUE
TRUE OR FALSE: Objects made from wrapper classes are immutable.
TRUE
TRUE OR FALSE: Swapping two elements in an array requires three assignment statements.
TRUE
TRUE OR FALSE: Switch statements can only test equality; they cannot make relational comparisons like greater than (>).
TRUE
TRUE OR FALSE: The print and println methods can be used to write data to a PrintWriter object.
TRUE
element type
The type of data that an array is declared to hold.
What does the following statement print? System.out.println((count < 0) ? "Invalid" : count);
The value of count, or "Invalid" if count is negative.
character encoding
The way in which those characters are stored in memory
If the value of weight is 7, what does the following statement print? System.out.println("The weight is " + ((weight % 2 == 0) ? "even" : "odd"));
The weight is odd
What output is produced by the following code? for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) System.out.print("*"); System.out.println(); }
***** ***** ***** ***** *****
What are the contents of the items array after the following code is executed? int[] items = {10, 20, 30, 40, 50}; for (int item : items) { item = item * 2; }
10, 20, 30, 40, 50
How many values can the heights array hold?
100
What value is printed by the following code? int count = 0; for (int i = 0; i < 5; i++) count += 3; System.out.println(count);
15
How many comparisons are necessary to find the value 43 in the following list using a binary search? 13 25 28 30 39 43 44 58 66 70 78 81 86 88 95
3
If the value of num is 7 and the value of max is 10, what is the value of num after the following statement is executed? num = (max < num) ? max : max - num;
3
What is the proper type designation for an ArrayList of Person objects?
ArrayList<Person>
Why is the input data for this program stored in an array after being read?
Because 2 passes through the data are needed to compute the result.
Why was the heights array declared to hold double values?
Because the input file contains floating-point values.
bounds error
Caused when you try to access an array element that doesn't exist.
non-printable characters
Characters (like newline) that have no visual symbol.
supplementary characters
Characters that don't map to the fixed-width, 16-bit Unicode encoding.
TRUE OR FALSE: A Scanner object can be used to both read and write text files in Java.
FALSE
TRUE OR FALSE: A binary search only works if the number of elements to search is odd.
FALSE
TRUE OR FALSE: A binary search works best on an unsorted list of values.
FALSE
TRUE OR FALSE: A for-each loop can be used to fill the values in an array.
FALSE
TRUE OR FALSE: A linear search examines every element in the array.
FALSE
TRUE OR FALSE: All Java wrapper classes are part of the java.util package.
FALSE
TRUE OR FALSE: An array of objects cannot be created with an initialization list.
FALSE
TRUE OR FALSE: Arrays can hold primitive types, but not objects.
FALSE
TRUE OR FALSE: Each value of a case can be a constant, variable, or expression.
FALSE
TRUE OR FALSE: If an array can hold N values, the valid indexes for that array range from 0 to N.
FALSE
What output is printed by the following code?What output is printed by the following code? String str = "Refactor Java"; int index = 0; int num = 0; while (index < str.length()) { if (str.charAt(index) == 'a') num++; index++; } System.out.println("Num: " + num);
Num: 3
Which one of the following constants and methods is NOT part of the Integer wrapper class?
POSITIVE_INFINITY
What is the element type of the athletes array in the ArrayOfPersonDemo program?
Person
What is the type of the variable athletes in the ArrayOfPersonDemo program?
Person[]
Which of the following declares a valid PrintWriter object that represents an output file named myOutput.txt?
PrintWriter out = new PrintWriter("myOutput.txt");
what kind of statement is the if statement
a conditional statement
what causes an infinite loop
a loop condition that is never false
What are the two terms that mean to automatically convert from a primitive value to a corresponding wrapper object and vice versa.
autoboxing and unboxing
TRUE OR FALSE: the string I prefer pi would be considered a palindrome by the original version of the program
false, even though it's in all lower case letters, the spaces would throw it off
TRUE OR FALSE: the number of times the while loop will be executed can be calculated before the loop begins
false, it depends on how long it takes the user to guess the target value
TRUE OR FALSE: it's impossible for user to guess the target value in one guess
false, it's possible but not likely
TRUE OR FALSE: the nested if statement in this program had to be written to check for the correct guess last
false, the logic of the if statement could be written to check any of the possibilities in any order
true or false: there is no way to stop an infinite loop
false, the program must be interrupted by pressing ctrl-c or ctrl break or by closing the run window
Which of the following correctly shows the general structure of a for-each loop header?
for (type variable-name : array-or-collection)
Going from left to right, what are the three sections of a for loop header?
initialization, condition, increment
Which method call will replace the element at index 3 of an ArrayList of String objects called stuff?
stuff.set(3, "new stuff")
TRUE or FALSE: The body of a while loop may never execute.
true
TRUE or FALSE: in some cases, a sentinel value can be used to signal the end of input
true
TRUE or FALSE: using a while loop to check each input value of correctness is a form of input validation
true
TRUE OR FALSE: This program would still work if the initial value of guess were set to -1 instead of -999.
true The value only needs to be outside of the target range.
TRUE OR FALSE: the inner loop will stop immediately if the string is determined not to be a palindrome
true, the boolean variable palindrome keeps track of it
TRUE OR FALSE: a potential palindrome is evaluated by comparing characters at both ends and working inwards
true, the indexes left and right determine which characters are compared
repetition statements
while for for-each do-while