CSE 205 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

128

Consider the recursive method myPrint in this code snippet: public void myPrint(int n) { if (n < 10){ System.out.print(n); } else { int m = n % 10; System.out.print(m); myPrint(n / 10); }} What is printed for the call myPrint(821)? A) 821 B) 12 C) 10 D) 128

return 1;

Insert the missing code in the following code fragment. This fragment is intended to recursively compute xn, where x and n are both non-negative integers: public int power(int x, int n){ if (n == 0) { ____________________ } else{ return x * power(x, n - 1); }} A) return power(x, n - 1); B) return x; C) return 1; D) return x * power(x, n - 1);

A Java interface must contain more than one method.

Which of the following statements about a Java interface is NOT true? A) A Java interface defines a set of methods that are required. B) A Java interface must contain more than one method. C) A Java interface specifies behavior that a class will implement. D) All methods in a Java interface must be abstract.

Each recursive method call takes processor time.

Why does the best recursive method usually run slightly slower than its iterative counterpart? A) Each recursive method call takes processor time. B) Multiple recursive cases must be considered. C) Checking multiple terminating conditions take more processor time. D) Testing the terminating condition takes longer.

Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses.

You are creating a class inheritance hierarchy about motor vehicles that will contain classes named Vehicle, Auto, and Motorcycle. Which of the following statements is correct? A) Vehicle should be the default class, while Auto and Motorcycle should be the subclasses. B) Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses. C) Vehicle should be the subclass, while Auto and Motorcycle should be the superclasses. D) Vehicle should be the subclass, while Auto and Motorcycle should be the default classes.

Stack

You need to access values in the opposite order in which they were added (last in, first out), and not randomly. Which collection type should you use? A) Hashtable B) Map C) Queue D) Stack

Abstract class.

A class from which you cannot create objects is called a/an ____. A) Abstract class. B) Concrete class. C) Non-inheritable class D) Superclass.

Label must be declared as an instance variable.

Consider the following code snippet: What is wrong with this code? A) label must be declared as an instance variable. B) button must be declared as an instance variable. C) Both label and button must be declared as instance variables. D) No error. It does work correctly.

n^3

Define the best (simplest) Big-Oh notation for each function, where the n is the number of elements. 1/2𝑛 ∙ (𝑛 ― 1) ∙ (𝑛 ― 2) = O

The instanceof operator.

To test whether an object belongs to a particular type, use ___. A) the this reserved word. B) the subclassOf reserved word. C) the instanceof operator. D) the equals method.

You can create an object from a concrete class, but not from an abstract class.

Which of the following statements about classes is true? A) You can create an object from a concrete class, but not from an abstract class. B) You can create an object from an abstract class, but not from a concrete class. C) You cannot have an object reference whose type is an abstract class. D) You cannot create subclasses from abstract classes.

The equals method is used to compare whether two objects have the same contents.

Which of the following statements about comparing objects is correct? A) The equals method is used to compare whether two references are to the same object. B) The equals method is used to compare whether two objects have the same contents. C) The == operator is used to compare whether two objects have the same contents. D) The equals method and the == operator are perform the same actions.

CashRegister class depends on Coin class

Which statement correctly describes the class relationship shown in this diagram? A) CashRegister class depends on Coin class B) Coin class depends on CashRegister class C) CashRegister class aggregates Coin class. D) Coin class inherits from CashRegister class.

Quiz class aggregates Question class.

Which statement correctly describes the class relationship shown in this diagram? A) Quiz class depends on Question class B) Question class aggregates Quiz class C) Quiz class aggregates Question class. D) Question class inherits from Quiz class

Car class inherits from Vehicle class.

Which statement correctly describes the class relationship shown in this diagram? A) Vehicle class depends on Car class B) Car class depends on Vehicle class C) Vehicle class inherits from Car class. D) Car class inherits from Vehicle class.

Subclass

A class that represents a more specific entity in an inheritance hierarchy is called a/an ____. A) Default class B) Superclass C) Subclass D) Inheritance class.

remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end.

A queue is a collection that ____. A) remembers the order of elements, and allows elements to be added and removed only at one end. B) remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end. C) does not remember the order of elements but allows elements to be added in any position. D) remembers the order of elements and allows elements to be inserted in any position.

Public abstract void act();

Abstract is used to design subclasses. Complete an abstract class ABC, which has a public void-type method act(). public abstract class ABC { ___________ }

(A)obj; -1 1

Add Java.lang.Comparable interface to class A. Complete the required compareTo method below. public class A implements Comparable { private int x; public A (int _x) {x = _x;} public int compareTo (Object obj){ A other =_________; if(this.x < other.x) return _________; else if (this.x > other.x) return _________; else return 0; }}

rect.xProperty().bind(slider.valueProperty()); or slider.valueProperty().addListener(event->{ rect.setX(slider.getValue());});

Add code and complete a program to change the x position of rectangle with the slider by binding the rectable's x and slider's value.

button = new Button("Like"); label = new Label("CSE205"); label.relocate(0, 50); button.setOnAction((event)->{ label.setText("Thank you"); });

Add code and develop a program to change the label from "CSE205" to "Thank you" when a button is clicked. Use the lambda expression, and relocate the label at (0, 50). public class Q21 extends Application { Button button; Label label; public void start(Stage stage) { ... Scene scene = new Scene(root, 100, 100); stage.setScene(scene); stage.show(); }}

if(e.getEventType() == MouseEvent.MOUSE_DRAGGED){ rect.setWidth (e.getX() - rect.getX()); rect.setHeight (e.getY() - rect.getY()); }

Add code and develop a program to change the width and height of rectangle during mouse dragged as shown below.

BorderPane pane = new BorderPane(); pane.setRight(new CustomPane("Right")); pane.setCenter(new CustomPane("Center")); pane.setBottom(new CustomPane("Bottom")); return pane;

Add code and develop a program to display the layout as shown below. Use and return the border pane in the createPane() method. public class Q22 extends Application{ public void start (Stage stage){ Scene scene1 = new Scene(createPane(), 200, 200); stage.setScene(scene1); stage.show();} public Pane createPane(){ ... } class CustomPane extends StackPane { public CustomPane (String name){ Label l = new Label(name); getChildren().add(l); setStyle("-fx-border-color: black"); setPadding(new Insets(11, 12, 13, 14)); }} }

KeyFrame k1 = new KeyFrame(Duration.seconds(2), new KeyValue(rect.xProperty(), 100)); KeyFrame k2 = new KeyFrame(Duration.seconds(3), new KeyValue(rect.xProperty(), 200)); Timeline anim = new Timeline(k1, k2);

Add code and develop a program to move a rectangle from (0,50) to (100, 50) in 2 seconds, and then move to (200, 50) in 3 seconds when a button is clicked. public class Q24 extends Application{ Rectangle rect; public void start (Stage stage){ Scene scene1 = new Scene(createPane(), 300, 150); stage.setScene(scene1); stage.show();} public Pane createPane(){ rect = new Rectangle(50, 50, 50, 50); Pane pane = new Pane(rect); ... Button b = new Button("Play"); pane.getChildren().add(b); b.setOnAction(event -> anim.play()); return pane; }}

if(n<=2) return 1 return fib(n-1)+ fib(n-2)

Add code, and complete the method to calculate the Fibonacci sequence. The following is to display the results from fib(2) to fib (49). public static void main(String[] arg){ for(int i =2; i<50; i++) System.out.println(i+":"+fib(i));; } public static long fib(int n){

They are all less than or equal to the pivot element

Assume we are using quicksort to sort an array in ascending order. What can we conclude about the elements to the left of the currently placed pivot element? A) They are all less than or equal to the pivot element B) They are all greater than or equal to the pivot element. C) They are all sorted. D) None can equal the pivot element.

2

Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes. A) 1 B) 2 C) 3 D) 4

4 8 5 2 9 4 9 5 2 8 9 4 5 2 8 9 8 5 2 4

Build (Heapify) a max-heap from the array containing the following: (the largest is stored at the root). Show all swaps to make it a max heap. 4 8 5 2 9

θ(n ∙ log(n)), θ(𝑛3/2), θ(𝑛3), θ(2𝑛)

Choose the order of the following growth rates, from slowest to fastest: θ(𝑛3), θ(n ∙log(n)), θ(𝑛3/2), θ(2𝑛). A) θ(n ∙ log(n)), θ(𝑛3/2), θ(𝑛3), θ(2𝑛) B) θ(𝑛3), θ(n ∙ log(n)), θ(𝑛3/2), , θ(2𝑛) C) θ(𝑛3/2), , θ(n ∙ log(n)), θ(𝑛3), θ(2𝑛) D) θ(2𝑛), θ(𝑛3), θ(𝑛3/2), , θ(n ∙ log(n))

This.level = level; this.hp = hp; this1.level = level; return level;

Complete a class file (.java file) for SuperHero based on the UML diagram below. public class SuperHero{ private int level; private int hp; public SuperHero(int level, int hp){ __________; __________;} public void setLevel(int level) { __________}public int getLevel() { __________}

return (anInteger * ( myFactorial(anInteger - 1) ));

Complete the code for the myFactorial recursive method shown below, which is intended to compute the factorial of the value passed to the method: public int myFactorial(int anInteger) { if (anInteger == 1) { return 1; } else{ ______________________ }} A) return (anInteger * ( myFactorial(anInteger - 1) )); B) return (anInteger * ( myFactorial(anInteger))); C) return ((anInteger - 1) * ( myFactorial(anInteger) ) ); D) return ((anInteger - 1)*( myFactorial(anInteger - 1) ) );

Int compare(Auto a, Auto b);

Complete the code shown to define the Comparator interface for comparing Auto objects. public interface Comparator<Auto>{ _____________________} A) boolean compare(Auto a, Auto b); B) single compare(Auto a, Auto b); C) single compareTo(Auto a, Auto b); D) int compare(Auto a, Auto b);

3*n < 1000 3n

Complete the snipped code to print out the values of 3n , until the value reaches 1000. for (int n=0; _______ ; n++) System.out.println( ______ );

35682417

Consider the following binary tree. Write the output of each traversal below using the tree. A) Pre-order Traversal

86524317

Consider the following binary tree. Write the output of each traversal below using the tree. B) In-order Traversal

86425713

Consider the following binary tree. Write the output of each traversal below using the tree. C) Post-order Traversal

Object

Consider the following code snippet of a function object. public interface Measurer{ double measure(______ anObject);} Complete this code to allow the interface to handle all classes? A) Class B) Object C) Any D) Void

s will contain the name of the consumerAuto object followed by a hash code.

Consider the following code snippet: Auto consumerAuto = new Auto(4, "gasoline"); String s = consumerAuto.toString(); Assume that the Auto class has not implemented its own toString() method. What value will s contain when this code is executed? A) s will contain the values of the instance variables in consumerAuto. B) s will contain only the name of the consumerAuto object. C) s will contain the name of the consumerAuto object followed by a hash code. D) This code will not compile.

The label and field should be added to the pane using pane.getChildren().add() method.

Consider the following code snippet: Pane pane = new Pane(); Label label = new Label("Show the answer"); TextField field = new TextField(); pane.add(label); pane.add(field); Which of the following statements is true? A) This code will correctly show all nodes. B) The label and field should be added to the pane using pane.getChildren().add() method. C) The pane should be created after making the label and field. D) The pane must be initialized with nodes without adding later.

The moveForward method of the Auto class will be executed.

Consider the following code snippet: Vehicle aVehicle = new Auto(); aVehicle.moveForward(200); If the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type, which statement is correct? A) The moveForward method of the Auto class will be executed. B) The moveForward method of the Vehicle class will be executed. C) You must specify in the code which class's moveForward method is to be used. D) It is not possible to determine which class's method is called.

The shape is moved always during mouse moved.

Consider the following code snippet: What is wrong with this code? A) The class cannot have empty blocks for the mouse pressed, mouse entered, and mouse exited cases. B) The shape is moved always during mouse moved. C) The class has implemented the wrong interface. D) The handle method cannot access the x and y coordinates of the mouse.

It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.

Consider the following code snippet: public class Motorcycle extends Vehicle{ . . . public Motorcycle(int numberAxles) { super(numberAxles); }} What does this code do? A) It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class. B) It invokes the constructor of the Motorcycle class from within the constructor of the Vehicle class. C) It invokes a private method of the Vehicle class from within a method of the Motorcycle class. D) This code will not compile.

Sizable.LARGE_CHANGE

Consider the following code snippet: public interface Sizable{ int LARGE_CHANGE = 100; void changeSize();} Which of the following indicates how to use the constant LARGE_CHANGE in your program? A) LARGE_CHANGE B) Sizable.LARGE_CHANGE C) Sizable(LARGE_CHANGE) D) You cannot directly use the LARGE_CHANGE constant in your program.

Insertion sort

Consider the following code snippet: public static void sort(int[] a){ for (int i = 1; i < a.length; i++) { int next = a[i]; int j = i; while (j > 0 && a[j - 1] > next) { a[j] = a[j - 1]; j--; } a[j] = next; }} What sort algorithm is used in this code? A) quick sort B) insertion sort C) merge sort D) selection

This method calls a public method in its superclass.

Consider the following code snippet: public void deposit(double amount){ transactionCount ++; super.deposit(amount);} Which of the following statements is true? A) This method will call itself. B) This method calls a public method in its subclass. C) This method calls a private method in its superclass D) This method calls a public method in its superclass.

The type parameter for the compareTo method must be the same as the implementing class.

Consider the following code snippet: public class BankAccount implements Comparable<BankAccount>{ . . . public int compareTo(T other) { What is wrong with this code? A) The type parameter for the Comparable interface in the implements clause must be the same as the implementing class. B) The type parameter for the Comparable interface in the implements clause must be the generic <T>. C) The type parameter for the compareTo method must be the same as the implementing class. D) The type parameter for the compareTo interface must be the generic <T>.

ab,abc,a,

Consider the following code snippet: What output will be produced when this code is executed? Queue<String> stringQueue = new LinkedList<>(); stringQueue.add("ab"); stringQueue.add("abc"); stringQueue.add("a"); while (stringQueue.size() > 0){ System.out.print(stringQueue.remove() + ",");} A) ab,abc,a, B) abc,ab,a, C) a,abc,ab, D) a,ab,abc,

a,abc,ab,

Consider the following code snippet: What output will be produced when this code is executed? Stack<String> stringStack = new Stack<>(); stringStack.push("ab"); stringStack.push("abc"); stringStack.push("a"); while (!stringStack.empty()){ System.out.print(stringStack.pop() + ",");} A) abc,ab,a, B) a,ab,abc, C) ab,abc,a, D) a,abc,ab,

[Mary, Robert, Sue]

Consider the following code snippet: What will be printed when this code is executed? LinkedList<String> myLList = new LinkedList<>(); myLList.add("Mary"); myLList.add("John"); myLList.add("Sue"); ListIterator<String> iterator = myLList.listIterator(); iterator.next();iterator.next(); iterator.add("Robert"); iterator.previous(); iterator.previous(); iterator.remove(); System.out.println(myLList); A) [Mary, John, Robert, Sue] B) [John, Robert, Sue] C) [Mary, Robert, Sue] D) [Mary, John, Sue]

defghiabc

Consider the following code snippet: What will this code print when it is executed? LinkedList<String> words = new LinkedList<>(); words.addFirst("abc"); words.addLast("def"); words.addFirst("ghi"); System.out.print(words.removeLast()); System.out.print(words.removeFirst()); System.out.print(words.removeLast()); A) ghiabcdef B) defghiabc C) abcdefghi D) abcghidef

Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class.

Consider the following inheritance hierarchy diagram: Which of the following statements is correct? A) Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class. B) Auto class inherits from LandVehicle class, and Vehicle class inherits from LandVehicle class. C) LandVehicle class inherits from Auto class, and LandVehicle class inherits from Vehicle class. D) LandVehicle class inherits from Auto class, and Vehicle class inherits from LandVehicle class.

18

Consider the following recursive code snippet: public int mystery(int n, int m) { if (n == 0) return 0; if (n == 1) return m; return m + mystery(n - 1, m);} What value is returned from a call to mystery(3,6)? A) 18 B) 3 C) 6 D) 729

Array[firstIndex]

Consider the helper method reversePrint, which uses recursion to display in reverse the elements in a section of an array limited by the firstIndex and lastIndex arguments. What statement should be used to complete the recursive method? A) array[firstIndex] B) array[firstIndex+1] C) array[lastIndex-1] D) array[lastIndex]

if(a[i] > a[maxPos]) { maxPos = i; }

Consider the minimumPosition method from the SelectionSorter class. Complete the code to write a maximumPosition method that returns the index of the largest element in the range from index from to the end of the array. A) if(a[i] == a[maxPos]) { maxPos = i; } B) if(a[i] <= a[maxPos]) { maxPos = i; } C) if(a[i] > a[maxPos]) { maxPos = i; } D) if(a[i] < a[maxPos]) { maxPos = i; }

The sort would produce correct results.

Consider the sort method shown below for selection sort: public static void sort(int[] a){ for (int i = 0; i < a.length - 1; i++) { int minPos = minimumPosition(i); swap(minPos, i); }} Suppose we modify the call to the swap method call to read swap(i, minPos). What would be the result? A) An exception would occur. B) The sort would produce incorrect results. C) The sort would produce correct results. D) The sort would work, but sort backwards.

return squareHelper(n, n)

Consider the square method shown below that takes a non-negative int argument. Complete the code for the square method so that it correctly calls the squareHelper method to produce the square of n. public int square(int n){ ____________________;} public int squareHelper(int c, int n) { if (c == 1){ return n; } else {return n + squareHelper(c - 1, n); }} A) return squareHelper(n - 1, n) B) return squareHelper(n, n - 1) C) return square(n) D) return squareHelper(n, n)

n^2

Define the best (simplest) Big-Oh notation for each function, where the n is the number of elements. a) 3𝑛^2 +3𝑛 ∙ log (𝑛) + 3 = O

Log(n)

Define the best (simplest) Big-Oh notation for each function, where the n is the number of elements. log(n^3) = O

n!

Define the best (simplest) Big-Oh notation for each function, where the n is the number of elements. n! + 2^n +n^100 + log(n^1000) = O

N

Define the best (simplest) Big-Oh notation for each function, where the n is the number of elements. n+(n+1)/2+(n+2)/3+(n+3)/4 = O

4

Given an ordered array with 15 elements, how many elements must be visited in the worst case of binary search? A) 2 B) 3 C) 4 D) 8

[6, 8, 2, 1, 0, 3, 5, 9] [6, 8, 2, 1] [0, 3, 5, 9] [6, 8] [2, 1] [0, 3], [5, 9] [6] [8] [2] [1] [0] [3] [5] [9] [6, 8] [1, 2] [0, 3] [5, 9] [1, 2, 6, 8] [0, 3, 5, 9] [0, 1, 2, 3, 5, 6, 8, 9]

Given the array [6, 8, 2, 1, 0, 3, 5, 9]. Show how the array is sorted in Merge Sort step by step. Use special symbols (such as [ ], |, *, etc.) to display the split and merged process clearly in your way.

[6, 8, 2, 1, 0, 3, 5, 9] [5, 8, 2, 1, 0, 3, 6, 9] [5, 3, 2, 1, 0, 8, 6, 9] (left side only) [0, 3, 2, 1, 5, 8, 6, 9] (left side only) [0, 3 ,2, 1, 5, 8, 6, 9] (left side only) [0, 1, 2, 3, 5, 8, 6, 9] (right side only) [0, 1, 2, 3, 5, 6, 8, 9] (right side only)

Given the array [6, 8, 2, 1, 0, 3, 5, 9]. When sorting the array using QuickSort, list up all changes of swapping. Use the first (left) element as a pivot.

A customer may have one or more bank accounts.

Given the following diagram:What does this diagram indicate about the relationship between the customers and bank accounts? A) A bank account may be owned by only one customer. B) A bank account may be owned by one or more customers. C) A customer may have only one bank account. D) A customer may have one or more bank accounts.

Void act(); // or public void act();

Implementing interface is another way to upgrade the class. Make the Actable interface which requires void-type act() method by completing the code below. public interface Actable { __________}

The smallest element not yet placed in prior iterations.

In each iteration, selection sort places which element in the correct location? A) The smallest in the array. B) The largest element in the array. C) A random element. D) The smallest element not yet placed in prior iterations.

Iter.hasNext()

Select an appropriate expression to complete the method below. The method should return the number of times that the string stored in name appears in theList. public static int count(LinkedList<String> theList, String name){ int number = 0; Iterator<String> iter = theList.iterator(); while (______________________){ if (iter.next().equals(name)) { number++;} } return number; } A) theList.next() != null B) iter.hasNext() C) theList.hasNext() D) iter.next() != null=!

45 36. 88 12. 49. 96 8

Show the Binary Search Tree (BST) that results when the following values are added, in order (added to the BST from left to right), to a new tree. 45 88 30 49 96 12 8

Implements Comparator public int camper(Player a, Player b) { return a.getHp() - b.getHP(); }

Suppose that Player class is given below. Make a PlayerComparator class implementing the Comparator<Player> interface and override the compare method to compare the hp (health power)..... public class PlayerComparator

Supert(_x); y = _y; super(_x, _y); z = _z;

Suppose that a class A has the custom constructor below. A custom constructor is to set the value of all instance variables with inputs, though the default constructor does not have not any input. public class A { private int x; public A (int _x) {x = _x;} } Complete the custom constructors of class B and C to set up the instance variables with the input. B is subclass of A, and C is subclass of B. public class B extends A{ private int y; public B (int _x, int _y){ __________ __________} } public class C extends B { private int z; public C (int _x, int _y, int _z){ __________ __________} }

AAACCC

Suppose that class A, B, and C are defined as below... What is the output of following code using class A, B, and C above. If there is a problem, write ERROR. public static void main(String[] args){ A obj1 = new B(); A obj2 = new C(); obj1.act(); obj2.act();}

BBBCCC

Suppose that class A, B, and C are defined as below... What is the output of following code using class A, B, and C above? public static void main(String[] args){ A obj1 = new B(); A obj2 = new C(); obj1.act(); obj2.act(); }

ERROR

Suppose that the Actable interface in the previous question is added to the class A, B, and C. What is the output of following code using class A, B, and C above? If there is a problem/compile error, write down "ERROR". public static void main(String[] args){ A obj1 = new B(); A obj2 = new C(); obj1.act(); obj2.act();}

A[3] list

Suppose that the class A implements the Comparable interface. Complete the code to sort the array of object A using Arrays.sort method. public static void main(String[] args){ A[ ] list = new _________; list[0] = new A(6); list[1] = new B(1, 2); list[2] = new C(3, 4, 5); Arrays.sort(_________);}

Private double bonus; return "*" + super.getName(); return bonus + supert.getSalary();

Suppose the class Employee is declared as follows... Declare a class Manager that inherits from the class Employee and 1) adds an instance variable bonus for storing a salary bonus, 2) override the getName() method of Empolyee so that managers have a "*" before their name (such as *Lin, Sally) and, 3) override the getSalary method so that it returns the sum of the salary and the bonus. Public class Manager extends Employee { __________ public String getName() { __________ } public double getSalary() { ___________ } }

public void changeRate(double newHourlyRate)

Suppose you are developing a payroll application that computes and displays weekly paycheck amounts for various employees. As a result of the design phase, the partial Employee class below is developed. Select the method header that best completes the class, according to the method comments. A) public void changeRate(double newHourlyRate) B) public void changeRate(double newHourlyRate, int hoursWorked) C) public double changeRate(double newHourlyRate) D) public double changeRate(double newHourlyRate, int hoursWorked)

public class Vehicle implements Comparable<Auto>

Suppose you wish to implement the Comparable interface to allow your Vehicle class to compare Auto objects only. Which of the following is the correct way to do this? A) public class Auto implements Comparable<Vehicle> B) public class Vehicle implements Comparable(Auto) C) public class Vehicle implements Comparable D) public class Vehicle implements Comparable<Auto>

(int j = 1; j < array.length; j = j * 2)

The code segment below prints some of the elements in an array with size n. Select an expression to complete the code segment so that the resulting algorithm has O(log n) running time. for __________________________ { System.out.println(array[j]);} A) (int j = 0; j < array.length; j = j + 2) B) (int j = 0; j < array.length / 2; j++) C) (int j = 1; j < array.length; j = j * 2) D) (int j = 0; j < array.length; j++)

first[iFirst] >second[iSecond]

The merge sort algorithm presented in section 14.4, which sorts an array of integers in ascending order, uses the merge method which is partially shown below. Select the condition that would be needed to complete the method so that the elements are sorted in descending order. A) first[iFirst] >second[iSecond] B) first[iFirst] <second[iSecond] C) iFirst > iSecond D) iFirst < iSecond

a[mid].compareTo(item)

The partial binary search method below is designed to search an array of String objects sorted in ascending order. Select the expression that would be needed to complete the method. A) a[low].compareTo(item) B) item.compareTo(a[mid]) C) item.equals(a[mid]) D) a[mid].compareTo(item)

smallButton.setToggleGroup(group);

The statement that would add smallButton to the button group in the following code is _________. RadioButton smallButton = new RadioButton("Small"); ToggleGroup group = new ToggleGroup(); A) group.add(smallButton); B) smallButton.setToggleGroup(group); C) smallButton.add(group); D) You cannot add smallButton to the button group.

Must use the same method name and the same parameter types.

To override a superclass method in a subclass, the subclass method ____. A) Must use a different method name. B) Must use the same method name and the same parameter types. C) Must use a different method name and the same parameter types. D) Must use a different method name and different parameter types.

JavaFX

What is the nickname for the latest graphical user interface library in Java? A) Applet B) GUI C) Swing D) JavaFX

0

What is the result of each operation in Java? System.out.println( (int) Math.random( ) * 250 );

50

What is the result of each operation in Java? System.out.println(250%100);

2

What is the result of each operation in Java? System.out.println(250/100);

2.5

What is the result of each operation in Java? System.out.println(250/100.0);

Ui

What is the result of each statement? String str = "ASUisAWESOME";System.out.println (str.substring(2, 4));

\"///

What is the result of each statement? System.out.println ("\\\"///");

12:S

What is the result of each statement? System.out.println (str.length( ) + ":" +str.charAt(1) ); "ASUisAWESOME"

SOME

What is the result of each statement? System.out.println (str.substring(8).toUpperCase()); "ASUisAWESOME"

True

What is the result of the snipped code below? Manager x = new Manager(); System.out.println(x instanceof Object);

Only by that class's methods, by all of its subclasses, and by methods in classes within the same package.

When declared as protected, data in an object can be accessed by ____. A) Only by that class's methods and by all of its subclasses B) Only by that class's methods, by all of its subclasses, and by methods in classes within the same package. C) Only by that class's methods. D) By any class.

Keyframes

When you make a timeline, you need to define ____ . A) Timer B) EventHandler C) Keyframes D) Duration

II and III

Which component can be added to a menu? I MenuBar II Menu III MenuItem A) I B) I and II C) II and III D) I, II and III

A Button object.

Which of the following is an event source? A) A Button object. B) An event handler. C) An inner class. D) An event adapter.

A subclass has no access to private instance variables of its superclass.

Which of the following is true regarding subclasses? A) A subclass has access to private instance variables of its superclass. B) A subclass does not have access to public instance variables of its superclass. C) A subclass must specify the implicit parameter to use methods inherited from its superclass. D) A subclass has no access to private instance variables of its superclass.

An interface has methods but no instance variables.

Which of the following statements about an interface is true? A) An interface has methods and instance variables. B) An interface has methods but no instance variables. C) An interface has neither methods nor instance variables. D) An interface has instance variables but no methods.

You can override methods in a class declared with the keyword final.

Which of the following statements about classes is NOT true? A) You cannot create an object from a class declared with the keyword final. B) You can override methods in a class declared with the keyword final. C) You cannot extend a class declared with the keyword final. D) You cannot create subclasses from a class declared with the keyword final.


Ensembles d'études connexes

Chapter 12. Milieu Therapy—The Therapeutic Community, Chapter 15. Promoting Self-Esteem, Chapter 11. Intervention With Families, Chapter 10. Therapeutic Groups, Chapter 4. Concepts of Psychobiology, Chapter 7. Relationship Development, Chapter 20. El...

View Set

Music appreciation Exam 1 Crowder

View Set

Chapter 28: Management of Patients with Structural, Infectious and Inflammatory Cardiac Disorders

View Set

Chapter 23 -- Potatoes, Grains and Pasta

View Set

ML 350- Final Exam (Multiple Choice)

View Set

The Peripheral Nervous System: Efferent Division

View Set

Chapter 1: Concepts and Trends in Healthcare

View Set