cs 1054 exam 2 quick checks

¡Supera tus tareas y exámenes ahora con Quizwiz!

T/F Arrays can hold primitive types, but not objects.

FALSE

T/F A Scanner object can be used to both read and write text files in Java.

FALSE A Scanner object is only used for input.

T/F A binary search only works if the number of elements to search is odd.

FALSE A binary search can be performed on any number of elements.

T/F A for-each loop can be used to fill the values in an array.

FALSE A for-each loop provides access to the elements in the array, but not to the array itself.

T/F A JavaFX event handler method for buttons must be called handleButtonPress.

FALSE An event handler method can be called whatever you'd like.

T/F An array of objects cannot be created with an initialization list.

FALSE Each element in the list has to be an object of the appropriate type.

T/F The leftmost end point of a line segment must be specified as the start point of the line.

FALSE Either point can be considered the start or end point.

T/F A binary search works best on an unsorted list of values.

FALSE For binary search to work at all, the list of values must already be sorted.

T/F Java represents a color using the CMYK color model.

FALSE Java uses the RGB color model.

T/F The parameters to the Rectangle constructor represent the upper left corner and lower right corner of the rectangle.

FALSE The first two represent the upper left corner, but the last two represent the rectangle's width and length, respectively.

T/F 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 The for loop could stay the same -- the condition of the if statement would change to find the biggest element.

T/F The Java coordinate system has the origin point (0, 0) in the lower left corner of a container.

FALSE The origin is in the upper left corner.

T/F If an array can hold N values, the valid indexes for that array range from 0 to N.

FALSE The valid range is 0 to N-1.

T/F All Java wrapper classes are part of the java.util package.

FALSE They are part of the java.lang package, and therefore don't have to be imported.

What does a change listener do? It reacts to a change in a control's status. It reacts to a change in an event handler. It reacts to a change in a property value. It reacts to a change in the GUI layout.

It reacts to a change in a property value. A change listener may be an appropriate alternative to an event handler.

T/F You can ignore the event generated when a check box is clicked.

TRUE You don't have to specify an event handler for a check box.

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 rapping and unrapping wrapping and unwrapping casting and uncasting

autoboxing and unboxing Converting a primitive type to an object is called autoboxing and going the other way is unboxing.

Which type of JavaFX node corresponds to a window? scene root node layout pane stage

stage

What is the output of the following code? int[] list = new int[5]; System.out.println(list[3]); 0 1 3 No output. No output because a bounds error occurs.

0

How many values can the heights array hold? 88 99 100 101

100 It's declared to hold 100 double values.

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 1 3 4 6

3 The elements examined, in order: 58, 30, 43

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 2 3 4 5

4 The elements examined, in order: 58, 81, 88, 86

What is a JavaFX layout pane? A node that contains all other nodes in the scene graph. A container that manages the visual presentation of the nodes it contains. A node that specifies the way in which the coordinate system axes are oriented. A window that displays a scene.

A container that manages the visual presentation of the nodes it contains.

What would happen if there were more than 100 values in the input file? The compiler would flag that situation as an error. A run-time error would occur. The extra data would be ignored. The array would be expanded automatically to accommodate the extra data.

A run-time error would occur. An ArrayIndexOutOfBoundsException would be thrown.

What analogy does JavaFX use for its high-level framework elements? a farm analogy a newspaper analogy a theater analogy a blueprint analogy

A theater analogy A scene is set on a stage

What is the proper type designation for an ArrayList of Person objects? ArrayList of Person ArrayList[Person] ArrayList<Person> Person ArrayList

ArrayList<Person> The element type is surrounded by < and > brackets.

Why is the input data for this program stored in an array after being read? Because the input data is formatted into rows and columns. Because the data needs to be processed twice to compute the result. Because the input is stored in a file. Because the formula requires a square root operation.

Because the data needs to be processed twice to compute the result. One pass to calculate the mean, the other to subtract the mean from each value.

Why was the heights array declared to hold double values? Because the input file contains floating-point values. Because the mean was computed as a double. Because the sumOfSquares variable is a double. Because the standard deviation result is a floating-point value.

Because the input file contains floating-point values. Each input value is stored in the array, so their types must be compatible.

Which of the following expressions represents the color white? Color.rgb(100, 0, 0) Color.rgb(255, 255, 255) Color.rgb(100, 100, 100) Color.rgb(0, 0, 0)

Color.rgb(255, 255, 255) Full contribution of red, green, and blue corresponds to white

T/F A toggle group is used to set the visual layout of its radio buttons.

FALSE A toggle group has nothing to do with the visual presentation of the buttons.

T/F It's important to understand array processing to understand how to use an ArrayList.

FALSE Although the ArrayList class uses an array internally, the details aren't necessary to use the class.

T/F Selecting a check box will automatically unselect any other check boxes in its group.

FALSE Check boxes are not explicitly grouped. Selecting a check box has no effect on any others.

T/F Only one radio button displayed in a window can be selected at any time.

FALSE Mutual exclusion is based on toggle groups, not windows.

T/F A linear search examines every element in the array.

FALSE Once the target element is found, there is no need to keep searching the array.

T/F Text color is determined by the font applied to a Text object.

FALSE Text color is specified using the setFill method of the Text class.

T/F When creating a Text object, you specify the position on which you want the text centered.

FALSE The coordinates specify where the leading (left) edge of the text begins.

T/F If left unspecified, the font applied to a Text object is 12 point Lucinda Grande.

FALSE The default font used depends on the operating system running the program.

T/F A parameter to the Button constructor specifies the event handler for the button.

FALSE The event handler is set separately.

T/F Each check box in your program must have its own event handler.

FALSE The events generated by multiple check boxes can be processed by the same event handler.

T/F The font applied to a Text object determines whether that text is underlined or not.

FALSE Underlining text is accomplished using the setUnderline method of the Text class.

T/F The event handler method for a Button must be called handleButton.

FALSE You can name an event handler method whatever you'd like as long as it accepts an ActionEvent parameter.

T/F An exception will be thrown if a radio button has not been made part of a toggle group

FALSE You don't have to set a radio button's toggle group, but it defeats the purpose if you don't.

What is the output of the following code? int sum = 0; int[] values = {1, 2, 3, 4, 5}; for (int i = 0; i <= 5; i++) sum = sum + values[i]; System.out.println("Sum: " + sum); Sum: 0 Sum: 5 Sum: 15 No output. A bounds error occurs

No output. A bounds error occurs The loop tries to access scores[5], but the last element in the array is scores[4].

Which statement is true about the following two circles? new Circle(50, 120, 50) new Circle(70, 120, 20) They have the same size. They have the same center point. They partially overlap. One fully surrounds the other (but they don't have the same center point).

One fully surrounds the other (but they don't have the same center point). The first circle completely surrounds the second.

Which one of the following constants and methods is NOT part of the Integer wrapper class? MIN_VALUE POSITIVE_INFINITY parseInt SIZE toBinaryString

POSITIVE_INFINITY Only Float and Double have this constant.

What is the element type of the athletes array in the ArrayOfPersonDemo program? String Person[] array[Person] Object Person

Person Each element in the athletes array is a Person object.

What is the type of the variable athletes in the ArrayOfPersonDemo program? Person[] String PersonArray Person ArrayOfPerson

Person[] That is the type of an array that holds Person objects.

Which of the following declares a valid PrintWriter object that represents an output file named myOutput.txt? PrintWriter out = new File("myOutput.txt"); PrintWriter out = new Scanner("myOutput.txt"); PrintWriter out = new PrintWriter(new File("myOutput.txt")); PrintWriter out = new PrintWriter("myOutput.txt");

PrintWriter out = new PrintWriter("myOutput.txt"); The PrintWriter constructor only needs the name of the file.

Which of the following declares a valid Scanner object to read an input file named myData.txt? Scanner in = new Scanner(new PrintWriter("myData.txt")); Scanner in = new Scanner(new File("myData.txt")); Scanner in = new Scanner("myData.txt"); Scanner in = new File("myData.txt");

Scanner in = new Scanner(new File("myData.txt")); An input file scanner is created by passing a File object to the Scanner constructor.

What is the element type of the adjectives array in the ArrayOfStringDemo program? array[String] String[] char int String

String The elements of the adjectives array are String objects.

What is the type of the variable adjectives in the ArrayOfStringDemo program? array[String] ArrayOfString String String[] StringArray

String[] That is the type of an array that holds String objects.

Which method call will replace the element at index 3 of an ArrayList of String objects called stuff? stuff.change(3, "new stuff") stuff.replace(3, "new stuff") stuff.add(3, "new stuff") stuff.set(3, "new stuff")

Stuff.set(3, "new stuff") The element that was at that position is replaced.

What is the output of the following code? int sum = 0; int[] values = {7, 6, 5, 4, 3, 2, 1}; for (int i = 1; i < values.length; i++) sum += values[i]; System.out.println("Sum: " + sum); Sum: 0 Sum: 7 Sum: 21 Sum: 28

Sum: 21 The sum is 21 because scores[0] is not included in the sum.

T/F File I/O operations may throw checked exceptions.

TRUE Since they are checked, your code must either handle them explicitly or at least acknowledge they may occur.

T/F An ArrayList is a collection that can be processed using a for-each loop.

TRUE An ArrayList is a common and useful collection.

T/F Swapping two elements in an array requires three assignment statements.

TRUE An extra variable is used to hold one value temporarily.

T/F Finding a minimum value requires that every element in the array be considered

TRUE Any of the values could be the minimum.

T/F An array of objects is really an array of object references.

TRUE Each cell of an array of objects holds only the address of the object.

T/F A for-each loop can be used to compute the sum of all values in an array

TRUE Each value can be added into a running sum as the for-each loop iterates over the elements.

T/F Whether text is displayed in bold or italic type is a function of the font object applied to the text.

TRUE Font weight and font posture are both attributes of the Font class.

T/F An output file should always be closed when you're done using it or data may be lost.

TRUE Forgetting to close an output file is a common error.

T/F An array that holds objects is, itself, an object.

TRUE In Java, all arrays are objects.

T/F An ArrayList cannot store primitive types such as int or double.

TRUE Instead, use wrapper classes to create ArrayList<Integer> or ArrayList<Double> objects.

T/F A wrapper class "wraps" a primitive value as an object.

TRUE It can be used in situations that are only appropriate for objects.

T/F If you try to access an element outside of the valid index range for an array, an exception will be thrown.

TRUE It will throw an ArrayIndexOutOfBounds exception.

T/F Traversing an array or collection means accessing each element one at a time.

TRUE It's a common activity that is facilitated by a for-each loop.

T/F Event-driven processing is used to respond to user actions in a program with a Graphical User Interface (GUI).

TRUE It's a wait-for-something-to-happen approach.

T/F The Swing API is an older approach to developing Java GUI programs that is no longer supported by Oracle.

TRUE JavaFX is now the preferred framework for Java graphics and GUIs.

T/F Radio buttons work in a group to provide a set of mutually-exclusive options.

TRUE Only one option can be selected at a time.

T/F In the ButtonDemo example, the handleButton method is called each time the button is pushed.

TRUE That method was set as the event handler method for the button.

T/F The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue.

TRUE The Java color model is based on this mechanism.

T/F Arial is an example of a font family.

TRUE The font family specifies the general look of the characters.

T/F A for-each loop cannot be used to set the values in an array.

TRUE The for-each loop automatically extracts the values already in the array; it can't be used to set values in the array.

T/F A for-each loop cannot be used to print the elements in an array backwards.

TRUE The for-each loop only processes array elements starting at index 0.

T/F A generic class operates on a generic type, which is specified when an object is created.

TRUE The generic type is specified by a placeholder such as E until instantiation.

T/F A Button can display text and an image at the same time.

TRUE The label on a button can display either or both.

T/F Objects made from wrapper classes are immutable.

TRUE The value of a wrapper object can't be changed once it has been created.

T/F A rectangle's corners can be rounded using calls to the setArcWidth and setArcHeight methods.

TRUE Their parameters determine the shape of the curve.

T/F Objects created from the Color class are immutable.

TRUE Their values cannot be changed once the color is created.

T/F The Text class and the Font class are part of the same package.

TRUE They are both part of the javafx.scene.text package.

T/F The print and println methods can be used to write data to a PrintWriter object.

TRUE They work just as they do in the System.out object

T/F An alpha channel value of 1.0 represents a fully opaque color.

TRUE This is the default. Alpha values less than 1.0 make the color translucent.

T/F A radio button can be part of only one toggle group.

TRUE You set the toggle group for each radio button rather than add a button to a group.

What does the fourth parameter in this method call represent? Color.rgb(100, 100, 200, 0.65); The key color (black) contribution The primary color ratio The color's hue The alpha channel (transparency)

The alpha channel (transparency) That color is a translucent blue.

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. An exception will be thrown when the program executes. The operation will be ignored. The string will be automatically converted to a Person object.

The compiler will issue an error message. The element added must be compatible with the declared element type.

What happens when an element is removed from an ArrayList? The element remains in the list but is marked as deleted. The remaining elements are shifted to close the gap. The element is replaced with a null reference. The element is moved to the end of the list.

The remaining elements are shifted to close the gap. The elements at higher indexes are all shifted by one position.

What type of event does a JavaFX Button generate when the button is pressed? press event button event action event change event

action event Several GUI controls generate action events.

What type of event does a check box generate when clicked? toggle event check event action event click event

action event A CheckBox object generates an action event when it is clicked.

What type of event does a Button produce when it is clicked with the mouse? click event push event action event press event

action event A button generates an action event each time it is pushed.

Which of the following is the preferred way to declare an array. double[] prices = new double[10]; double prices[] = new double[10];

double[] prices = new double[10]; By placing the brackets immediately after the element type of the array, your code is more readable.

When performing a binary search, how many comparisons are required to find a value in a list of N values, in the worst case? 1 log2N + 1 N / 2 N^2

log2N + 1

Which of the following circles is largest? new Circle(150, 175, 45) new Circle(50, 50, 50) new Circle(20, 100, 30) new Circle(30, 80, 25)

new Circle(50, 50, 50) This circle, with a radius of 50, is larger than any of the others.

Which of the following ellipses is also a circle? new Ellipse(100, 200, 55, 55) new Ellipse(150, 150, 150, 100) new Ellipse(70, 70, 100, 70) new Ellipse(95, 120, 95, 120)

new Ellipse(100, 200, 55, 55) The width and height of this ellipse are the same.

Which of the following ellipses is thinner than it is tall? new Ellipse(150, 135, 80, 60) new Ellipse(270, 300, 180, 100) new Ellipse(140, 100, 20, 50) new Ellipse(90, 90, 60, 55)

new Ellipse(140, 100, 20, 50) The X radius of this ellipse is smaller than its Y radius.

Which of the following lines is horizontal? new Line(30, 30, 50, 50) new Line(75, 20, 75, 90) new Line(25, 70, 125, 70) new Line(40, 20, 100, 70)

new Line(25, 70, 125, 70) The y coordinates of both end points are the same.

Which of the following rectangles extends furthest down? new Rectangle(100, 50, 50, 100) new Rectangle(80, 25, 100, 130) new Rectangle(150, 90, 70, 45) new Rectangle(50, 85, 70, 75)

new Rectangle(50, 85, 70, 75) This rectangle extends to 160 on the y axis, further than any of the others.

What Button method is called to set the event handler for the button? setEventHandler setOnAction setListener setHandler

setOnAction The setOnAction method associates the button with its event handler.

Which of the following would be most appropriate to choose with a set of check boxes? the highest educational level you've achieved your gender the languages you speak your favorite ice cream flavor

the languages you speak You could check all of the languages you speak.

Which of the following correctly shows the general structure of a for-each loop header? for (initialization; condition; increment) foreach (type variable-name : array-or-collection) foreach (value array : condition; array-length-specifier) for (type variable-name : array-or-collection)

for (type variable-name : array-or-collection) On each iteration the next element can be accessed using the specified variable.

Which of the following is NOT a GUI control? button handler check box text field

handler An event handler processes events fired by a control.


Conjuntos de estudio relacionados

Old Testament: Topic 6 and 7 Review

View Set

Series 65 Unit 3: Pooled Investments

View Set

Entrepreneurship - Chapters 5 & 6

View Set

Reproductive System: Regulation of the Ovarian Cycle

View Set

10 Best Job Interview Tips for Job -Seekers

View Set

Business Law CH 32 (agency formation and duties)

View Set

Chapter 16: Nose, Mouth, and Throat multiple choices, Chapter 15 Health Assessment quiz, Chapter 14, Ch. 13 - Head, Face, and Neck, Including Regional Lymphatics, Chapter 5: Mental Status (Jarvis), Chapter 12: Skin, Hair, and Nails Jarvis: Physical E...

View Set

Agricultural Geography: Agricultural Regions and Cultivation

View Set