cse quizzes

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

Question 81 / 1 pts If an int array is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header?

(int [ ] a)

assume node temp references the last element of the linked list. which of the following conditions is true about temp?

(temp.next == null)

Use the following recursive method. public int question(int x, int y){ if (x == y) return 0; else return question(x-1, y) + 1; } Calling this method will result in infinite recursion if which condition below is initially true?

(x < y)

Reasons for using nested classes:

-A nested class can access all members of the class containing it even if these members are private. -It is a way of logically grouping classes that are only used in one place. -It can lead to more readable and maintainable code.

How are interfaces, abstract classes, and inherited classes different?

-Interfaces are implemented using the 'implements' keyword. Inherited classes and abstract classes are inherited using the 'extends' keyword. -A particular class can inherit only one class using the 'extends' keyword while a class can implement multiple interfaces. -An abstract class can have both abstract and non-abstract methods. An interface can have only abstract methods. A normal inherited class can't have any abstract methods. -Variables declared in a java interface are by default final. Abstract classes and inherited classes can have non-final variables. -Members of an interface are public by default. An abstract class and inherited class can have non-public members also.

D E B I A F K G C H J 1. Produce a preorder traversal of this tree. 2. Produce a inorder traversal of this tree. 3. Produce a postorder traversal of this tree. 4. Produce a level-order traversal of this tree. 5.Draw an array to represent this tree

1. Preorder traversal: D E I A G C J B F K H 2. Inorder traversal: I E G A C J D F B H K 3. Postorder traversal: I G J C A E F H K B D 4. Level-order traversal: D E B I A F K G C H J 5. D=0 E=1 B=2 I=3 A=4 F=5 K=6 G=9 C=10 H=13 J=22

Exception Handling

1. Using try statements. The line that throws the exception are included within the block of try statement. A catch block is used to indicate the particular type of exception to be caught. A finally block can be used to execute a particular statement irrespective of whether an exception occurs or not. 2. Using throws clause. The appropriate exception is appended to the header of a method definition where the exception is thrown.

Perform the partition method of quick sort once on the array [11, 7, 15, 3, 12, 9, 2, 10]. Show the array after each iteration of the while loop in the partition method. Use the first element (here it is 11) as the pivot.

11,7,15,3,12,9,2,10 -> i j <- SWAP 10,7,15,3,12,9,2,11, i j SWAP 10,7,2,3,12,9,15,11, i j SWAP 10,7,2,3,9,12,15,11, j i STOP Thus, this is partitioned into [10, 7, 2, 3, 9] and [12, 15, 11]

Demonstrate how the following array is sorted using Merge Sort. Show the array after each recursive call (after merging). [12, 3, 5, 4]

12 3 5 4 12 3 5 4 12 3 5 4 3 12 4 5 3 4 5 12

For next question, assume a Stack class stores int values. Consider the following sequence of instructions. Stack s = new Stack( ); s.push(16); s.push(12); s.push(19); int x = s.pop( ) ;s.push(5); s.push(9); s.push(4); int y = s.pop( ); int z = s.pop( ); After the instructions execute, x has the value

19

For next question, assume a Stack class stores int values. Consider the following sequence of instructions. Stack s = new Stack( ); s.push(16); s.push(12); s.push(19); int x = s.pop( ); After the instructions execute, x has the value

19

assume a linked list consists of node objects, where node has two instances of data, int info and node next. the linked list stores in the info data, 20, 11, 13, 19, 12, 14, in that oder. assume node references the first item in the list. what will be returned by head.next.next.next.info;?

19

assume a linked list consists of node objects, where node has two instances of data, int info and node next. the linked list stores in the info data, 20, 11, 13, 19, 12, 14, in that oder. assume node references the first item in the list. what will be returned by head.info;?

20

What will be the output of the following code snippet? int [] array = new int[25]; System.out.println(array.length);

25

For next question, consider the following operations on a Queue data structure that stores int values. Queue q = new Queue( ); q.enqueue(5); q.enqueue(6); q.enqueue(7); System.out.println(q.dequeue( )); // d1 q.enqueue(9); System.out.println(q.dequeue( )); // d2 System.out.println(q.dequeue( )); // d3 q.enqueue(2); q.enqueue(8); After the code above executes, how many elements would remain in q?

3

For next question, consider the following operations on a Queue data structure that stores int values. Queue q = new Queue(); q.enqueue(3); q.enqueue(5); q.enqueue(9); System.out.println(q.dequeue( )); q.enqueue(2); q.enqueue(4); System.out.println(q.dequeue( )); System.out.println(q.dequeue( )); q.enqueue(1); q.enqueue(8); After the code above executes, how many elements would remain in q? 1. 0 2. 4 3. 5 4. 6 5. 7

4

Write the output generated by the following program public class TestWierdPowerMethod { public static int pow( int base, int power ){ // pre: both arguments are >= 1 if( power == 1 ) return base; elsereturn base * pow( base, power-1 ); } public static void main(String[] args) { System.out.println( pow(4, 1) ); System.out.println( pow(4, 2) ); System.out.println( pow(4, 3) ); }}

4 16 64

Use the following recursive method. public int question(int x, int y){ if (x == y) return 0; else return question(x-1, y) + 1; } If the method is called as question(8, 3), what is returned?

5

For next question, consider the following operations on a Queue data structure that stores int values. Queue q = new Queue( ); q.enqueue(5); q.enqueue(6); q.enqueue(7); System.out.println(q.dequeue( )); // d1 q.enqueue(9); System.out.println(q.dequeue( )); // d2 System.out.println(q.dequeue( )); // d3 q.enqueue(2); q.enqueue(8); If we replace the System.out.println statements (denoted in comments as d1, d2 and d3) with the statement q.enqueue(q.dequeue( )); q would contain which order of int values after all instructions have executed?

5, 9, 6, 7, 2, 8

Assume that the countIt and sumIt methods in next two questions receive a parameter Node temp, which references the first Node in a linked list where Node is a class that consists of data instances int info and Node next and further assume that the int variables count and sum are initialized to 0. 5. Write a method to count the number of items in the linked list? 6. Write a method to sum all of the items in the linked list?

5. public int countIt(Node temp) { while (temp != null) { count++; temp = temp.next; } return count; } 6. public int sumIt(Node temp) { while (temp != null) { sum += temp.info; temp = temp.next; } return sum; }

Refer to the following recursive factorial method. public int factorial(int x) { if (x > 1) return x * factorial (x - 1); else return 1; } What is returned if factorial(3) is called?

6

For next question, consider the following operations on a Queue data structure that stores int values. Queue q = new Queue( ); q.enqueue(5); q.enqueue(6); q.enqueue(7); System.out.println(q.dequeue( )); // d1 q.enqueue(9); System.out.println(q.dequeue( )); // d2 System.out.println(q.dequeue( )); // d3 q.enqueue(2); q.enqueue(8); What value is returned by the last dequeue operation (denoted above with a d3 in comments)?

7

Write out the order of elements that are contained in a stack after the following operations are performed. myStack.push(new Integer(8)); myStack.push(new Integer(6)); Integer num1 = myStack.pop(); myStack.push(new Integer(3)); myStack.push(new Integer(4)); myStack.push(new Integer(15)); myStack.push(new Integer(12)); myStack.push(new Integer(9)); myStack.pop(); myStack.pop(); myStack.pop(); myStack.push(new Integer(19));

8 3 4 19 (from bottom to top of stack)

Write the output generated by the following code using the LinkedStack class: Stack opStack = new LinkedStack( ); System.out.println( opStack.isEmpty( ) ); opStack.push( ">" ); opStack.push( "+" ); opStack.push( "<" ); System.out.print( opStack.peek( ) ); System.out.print( opStack.peek( ) ); // careful System.out.print( opStack.peek( ) );

< < <

What happens if you attempt to open a nonexistent file using FileOutputStream?

A file with the name will be created.

If you have a pane named "pane1" and an inner listener class named "PaneHandler", how do you register the "pane1" to listen to the mouse pressed event?

pane1.setOnMousePressed(new paneHandler());

An example of an aggregation relationship is

parent and child

Which of the following lists of commands is used to see the top item of a Stack without removing it from the Stack?

peek

The idea that an object can exist separate from the executing program that creates it is called

persistence

For next question, assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... are the required parameters for the constructors: Person p = new Person(...); int m1 = p.getMoney( ); // assignment 1 p = new Student(...); int m2 = p.getMoney( ); // assignment 2 if (m2 < 100000) p = new Employee(...); else if (m1 > 50000) p = new Retired(...); int m3 = p.getMoney( ); // assignment 3 The reference to getMoney( ) in assignment 1 is to the class

person

A variable declared to be of one class can later reference an extended class of that class. This variable is known as

polymorphic

Binary Tree traversals - consider the following tree: 42/ \18 33/ \ \55 86 21/ \42 45 Show how the tree would be printed using each of the traversals below: Preorder traversal: Inorder traversal: Postorder traversal:

preorder: 42, 18, 55, 42, 86, 45, 33, 21 inorder: 42,55,18,86,45,42,33,21 postorder: 42,55,45,86,18,21,33,42

Write a method sumAlternate that computes and returns the sum of every other value in the list starting with the first one. For example, if the original list is: 1 2 3 4 5 this method would return 9.

public int sumAlternate() { Node current = head; int sum = 0; boolean everyOther = true; while(current != null) { if(everyOther) { sum += current.value; everyOther = false; } else everyOther = true; current = current.next; } return sum; }

Write a method sumEvens that computes and returns the sum of all even numbers in the list. .For example, if the original list is: 1 2 3 4 5 this method would return 6

public int sumEvens() { Node current = head; int sum = 0; while(current != null) { if(current.value % 2 == 0) sum += current.value; current = current.next; } return sum; }

which of the following methods could be used to count the number of items in the linked list?

public int countIt(Node temp){ while(temp!=null){ count++; temp=temp.next; } return count; }

The class Name consists of 4 instance data, String title, String first, String middle, String last. The class has a constructor that is passed all 4 String values and initializes the class appropriately, and has 4 methods, each returns one of the four instance data, called getTitle( ), getFirst( ), getMiddle( ) and getLast( ). Name[ ] addressBook = new Name[100];is performed. Write a methodthat is passed 4 String parameters corresponding to a Name's title, first, middle, and last, and finds this Name in addressBook and returns the index of where this Name was found, or -1 if the Name was not found. Assume that addressBookstores n entries (n is an int).

public int findName(String title, String first, String middle, String last){ for (int j=0; j<n; j++) if (title.equals(addressBook[j].getTitle( ) &&first.equals(addressBook[j].getFirst( ) &&middle.equals(addressBook[j].getMiddle( ) &&last.equals(addressBook[j].getLast( )) return j; return -1;

Write a recursive method int power(int i, int j)which determines the result of ijwhere j >= 0.

public int powerR(int i, int j) { if (j == 0) return 1; // i0= 1 for any i else return powerR(i, j-1) * i; // ij = ij-1* i= power(i, j-1)*i }

Assume that the linked list has at least two Nodes in it. Which of the following instructions will return the second int value in the list?

return head.next.info;

During program development, software requirements specify

what the task is that the program must perform

Assume Node temp is currently set equal to head. Which of the following while loops could be used to iterate through each element of a linked list?

while (temp != null) temp = temp.next;

assume node temp is currently set equal to head. which of the following while loops could be used to iterate through each element of a linked list?

while(temp!=null) temp=temp.next;

Use the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following lists of instance data are accessible in class A2?

x, z, a, b

Use the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following lists of instance data are accessible in A3?

x, z, a, q

What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a complexity of O(1)? for(int i = 0; i < array.length; i++) for(int j = 0; j< array.length; j++) someMethod(array[j])

O(n^2)

Is Java aFunctional Language, Procedural Language, Object-Oriented Language, or Logic Language?

Object-Oriented

Of the various phases in software development, which of the following is usually the lengthiest?

maintenance

The advantage of creating a BookList using a linked list instead of using an array is that the linked list

is dynamic and so can be any size needed

The relationship between a parent class and a child class is referred to as a(n) ____ relationship.

is-a

Use the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following is true regarding the use of instance data y of class A1?

it is accessible only in A1

which of the following criticisms of an array is applicable to a java array?

it is fixed in size (static)

assume a linked list consists of node objects, where node has two instances of data, int info and node next. the linked list stores in the info data, 20, 11, 13, 19, 12, 14, in that oder. assume node references the first item in the list. what will head.next.next = head.next.next.next; accomplish?

it will result in the value 13 being deleted from the list

Consider the following class definition: public class Quiz{ private int x; public Quiz(int newValue) { x = newValue; } } Which of the following is true about the class Quiz?

it's parent class is Object

Every Java array is a(n) _________________, so it is possible to use a foreach loop to process each element in the array.

iterator

What is the efficiency of binary search?

log2n

Assume that you will want to save, using object serialization, a Book object in a file. Write a class definition (Book.java) for Book class using the following UML class diagram. This class has only one method, a constructor that assigns values to each instance variable. Then write a complete Java program (driver class with a main () method) to instantiate a Book object with some title, price and bookId (you can decide on them) and store it in a file called "book.dat". Book -title : String -price: doube -bookId : int+Book(String, double, int)

// Book.java import java.io.Serializable; public class Book implements Serializable{ private String title; private double price; private int bookId; public Book(String title, double price, int bookId){ this.title = title; this.price = price; this.bookId = bookId; }} // Driver class (Driver.java)import java.io.*; public class Driver{ public static void main(String[] args){ Book book1 = new Book("Java Programming", 80.50, 12345); FileOutputStream file =null; ObjectOutputStream outStream = null; try{ file = new FileOutputStream("book.dat"); outStream = new ObjectOutputStream(file); outStream.writeObject(book1); } catch(IOException ex){ System.out.println("IOException"); } //the following is optional catch(NotSerializableException ex){ System.out.println("The object is not serializable"); } finally{ try { if (outStream != null) outStream.close(); } catch (IOException exc){ System.out.println(exc); }}} //end of main method } //end of Driver class

Convert the following iterative method to a recursive one: public intIterativeFactorial(intn){ inti = 0; intresult = 1; while(i <= n -1){ result = result * (n -i); i++; } returnresult; }

//initial call from main with i = 0 public intRecursiveFactorial(intn, inti){ if (i == n -1)return1; else returnRecursiveFactorial(n, i + 1)* (n -i); }

When drawing a rectangle, Rectangle r1 = new Rectangle(A, B, C, D);A and B specify what property of the rectangle to be drawn? C and D represent what other property?

A and B specify the co-ordinate of top-left corner of the rectangle. A specifies the x co-ordinate and B specifies the y co-ordinate. C and D specifies the width and height of the rectangle respectively.

What is a wrapper class?

A wrapper class represents a particular primitive data type. In other words, we can wrap a primitive value into a wrapper class object. (primitive data types - int, double, char, boolean, and so on)

Use the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ...} Which of the following is true with respect to A1, A2 and A3?

A3 is a subclass of A2 and A2 is a subclass of A1

Why shouldn't an abstract method be declared final?

Abstract methods cannot be overridden - and they must be if a concrete class ever is to be instantiated

What is an ADT (an Abstract Data Type) and why are they considered to be "abstract?"

An ADT is a collection of data and the particular operations that are allowed on that data. An ADT has a name, a domain of values, and a set of operations that can be performed. An ADT is considered to be "abstract" because the operations you can perform are separated from the underlying implementation. That is, the details on how an ADT stores its data and accomplishes its methods are separate from the concept that it embodies

What does acronym API stands for?

Application Programming Interface

Replace the comment in the code below so that it produces the layout shown. public void start(Stage primaryStage) {Button vegies = new Button("Vegies");Button beans = new Button("Beans");Button rice = new Button("Rice");//instantiate the beer button & the TextArea /* create layout and set root here */Scene scene = new Scene(root, 300, 250);primaryStage.setScene(scene);primaryStage.show();}

Button beer = new Button("Beer"); TextArea textArea = new TextArea("This is a text area"); BorderPane root = new BorderPane(); root.setTop(vegies); root.setBottom(beer); root.setLeft(beans); root.setRight(rice);

Different types of exceptions

Checked exceptions: must be caught by a method (try and catch) or be listed in the throws clause. These exceptions are checked during compile time. Unchecked exceptions: Should not be caught and requires no throws clause. These exceptions are checked at run-time.

Which option draw a red circle with center at (100, 100) and radius 25.

Circle shape1 = new Circle(100, 100, 25); shap1.setFill(Color.RED);

Which code creates a ComboBox called 'comboColor" and assign the following strings options choose from: "Black", "Blue" and Yellow" it?

ComboBox comboColor = new ComboBox(); comboColor.getItems().addAll("Black", "Blue" , "yellow);

What are the objects needed in order to create a Java FX GUI (graphical user interface) that responds to user action(s)?

Control, event and listener objects

Classes in a software system can have various types of relationships to each otherList the three of the most common relationships:

Dependency: A uses B Aggregation: A has-a B Inheritance: A is-a B

How do you draw a line, a circle, a text and etc using the class Shape?

Drawing a line:................... Line line = new Line(startX, startY, endX, endY); Drawinga circle:..................... Circle circle = new Circle(centerX, centerY, radius); Drawing a text:.................. Text text = new Text(stratX, startY, stringToDisplay);

A postfix expression can be easily evaluated using a queue.

FALSE, A postfix expression can be easily expressed using a stacK

It is only possible to implement a queue using an array-based structure

FALSE, A queue can be implemented using a linked structure or an array-based structure.

It is only possible to implement a stack using a linked structure.

FALSE, A stack can be implemented using a linked structure or an array-based structure.

In a linked structure, the last node often requires special handling

FALSE, In a linked structure, the first node often requires special handling

Inserting an element into the middle of a linked list structure requires all of the elements to be shifted.

FALSE, Inserting an element into the middle of an array requires all of the elements to be shifted. Inserting an element into the middle of a linked list requires the manipulation of several pointers

What is printed by the following code? Consider the polymorphic invocation. class Figure { void display( ) { System.out.println("Figure"); }} class Rectangle extends Figure { void display( ) { System.out.println("Rectangle"); }} class Box extends Figure {void display( ) { System.out.println("Box"); }} class TestInherit{ public static void main(String[ ] args) { Figure f = new Figure( ); Rectangle r = new Rectangle( ); Box b = new Box( ); f.display( ); f = r; f.display( ); f = b; f.display( ); } }

Figure Rectangle Box

What is printed by the following code? Consider the polymorphic invocation. public class Inherit{ class Figure{ void display( ){ System.out.print(" Figure"); }} class Rectangle extends Figure{ void display( ){ System.out.print(" Rectangle"); }} class Box extends Figure{ void display( ){ System.out.print(" Box"); }} Inherit( ){ Figure f = new Figure( ); Rectangle r = new Rectangle( ); Box b = new Box( ); f.display( ); f = r; f.display( ); f = b;f.display( ); } public static void main(String[ ] args){ new Inherit( ); }}

Figure Rectangle Box

What happens if you attempt to open a nonexistent file using FileInputStream?

FileNotFoundException will be thrown.

[first] > ["First"| ] > ["Second"| ] > ["Third"| null] . Use the linked structure above to answer the following questions? What is the value of first.data? What is the value of first.next.data? What is the value of first.next.next.data? What is the value of first.next.next.next?

First Second Third null

What is the output of the code: import java.util.*; public class ListTester{ public static void main(String[] args){ LinkedList <String> staff = new LinkedList<String>(); staff.addFirst("Orange"); staff.addFirst("Red"); staff.addFirst("Blue"); staff.addFirst("Green"); ListIterator<String> iterator = staff.listIterator(); iterator.next(); iterator.next(); // Add more elements after second element iterator.add("Yellow"); iterator.add("White"); iterator.next(); iterator.remove(); // Print all elements ListIterator<String> it2 = staff.listIterator(); while (it2.hasNext()) { String element = it2.next(); System.out.print(element + " "); }}}

Green Blue Yellow White Orange

If you want to display three components vertically in a container of any size, what layout could you NOT use?

HBox layout

Nested and non-nested class

If a class A is declared inside another class B, then that class A is called a nested class. Otherwise, if both classes A and B are declared independently within different file, then class A and B are called non-nested classes.

Which of the following statements is completely true?

If a class is declared to be abstract then some methods in the class may have their bodies omitted

For the following Array show how the array would be sorted using Insertion sort after each pass of the outer loop. [9,6,14,11,3,12,7,5]

Insertion sort: [6,9,14,11,3,12,7,5] [6,9,14,11,3,12,7,5] [6,9,11,14,3,12,7,5] [3,6,9,11,14,12,7,5] [3,6,9,11,12,14,7,5] [3,6,9,11,12,14,7,5] [3,6,7,9,11,12,14,5]

If you have a text field called, textField, that is suppose to hold an integer, what expression do you use to read its contents?

Integer.parseInt(textField.getText())

Consider the following line of code. Comparable s = new String();Which of the following statements is true about this line?

It will create a String object pointed to by a Comparable reference.

What is the comparable interface used for and what is the signature of the method that needs to be defined by the implementing the class.

Java Comparable interface is used to sort or order the objects of a user-defined class. The sort can be done on various properties of the class. Comparable cannot sort the objects on its own, but the interface defines a methodto achieve this goal.

Which code below draws a letter "V" by drawing two line segments?

Line shape1 = new Line(0, 0, 10, 30); Line shape1 = new Line(10, 30, 20, 0);

Show the instructions required to create a linked list that is referenced by head and stores in order, the int values 3, 6 and 2. Assume that Node's constructor receives no parameters

Node head = new Node( ); head.info = 3; head.next = new Node( ); head.next.info = 6; head.next.next = new Node( ); head.next.next.info = 2; head.next.next.next = null;

which of the following instructions would create an initially empty linked list?

Node head = null;

Assume that head references a linked list that stores the values 3, 6 and 2 in that order. Show the instructions needed to move the value 2 in front of the value 6 (so that the list is now 3, 2, 6)

Node temp = head.next; head.next = head.next.next; head.next.next = temp; temp.next = null;

What happens if you attempt to store an object that is not an instance of Serializable?

NotSerializableException will be thrown.

Demonstrate how the following array is sorted using Selection Sort. Show the array after each pass of the outer loop. [10, 4, 3, 12, 7]

Pass 1: 3 4 10 12 7 Pass 2: 3 4 10 12 7 Pass 3: 3 4 7 12 10 Pass 4: 3 4 7 10 12

A ___________ is a component (node) that can be either selected or deselected. These components usually appear in a group so that only one of them in the group can be selected at a time.

RadioButton

For the following Array show how the array would be sorted using Selection sort after each pass of the outer loop. [9,6,14,11,3,12,7,5

Selection sort: [3,6,14,11,9,12,7,5] [3,5,14,11,9,12,7,6] [3,5,6,11,9,12,7,14] [3,5,6,7,9,12,11,14] [3,5,6,7,9,12,11,14] [3,5,6,7,9,11,12,14] [3,5,6,7,9,11,12,14]

For next question, assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... are the required parameters for the constructors: Person p = new Person(...); int m1 = p.getMoney( ); // assignment 1 p = new Student(...); int m2 = p.getMoney( ); // assignment 2 if (m2 < 100000) p = new Employee(...); else if (m1 > 50000) p = new Retired(...); int m3 = p.getMoney( ); // assignment 3 The reference to getMoney( ) in assignment 2 is to the class

Student

use the following class definition import java.text.DecimalFormat; public class Student{ private String name; private String major; private double gpa; private int hours; public Student(String newName, String newMajor, double newGPA, int newHours){ name = newName;major = newMajor;gpa = newGPA; hours = newHours;}public String toString( ){ DecimalFormat df = new DecimalFormat("0.000"); return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours}} Which of the following could be used to instantiate a new Student s1?

Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33);

What methods do you use to get the location of the mouse when implementing Mouse Event?

Suppose, event is a MouseEvent object. Then, we can get the location of mouse using two different ways: First way:............Point point = event.getPoint();Point.x indicates the x co-ordinate and point.y indicates the y co-ordinate. Second way:...................event.getX()and event.getY()methods can be used to get the x and y co-ordinate respectively.

Assume that x is a double that stores 0.362491. To output this value as 36%, you could use the NumberFormat class with NumberFormat nf = NumberFormat.getPercentInstance( ); Which of the following statements then would output x as 36%?

System.out.println(nf.format(x));

. A linked structure uses references to allow items to point to each other in the collection.

TRUE, A linked structure uses references to organize the structure

A queue is a FIFO structure.

TRUE, A queue is a FIFO structure, meaning that the first element that is put in is the first element that is inserted is the first element that is removed. FIFO stands for first-in-first-out.

A stack is a LIFO structure.

TRUE, A stack is a LIFO structure, meaning that the last element that is inserted is the first element that is removed. LIFO stands for last-in-first-out

What is the complexity of the following code (in terms of the length of the array)? for(int i = 0; i < 5; i++) System.out.println(array[i]);

The complexity of this code is O(1), since the length of the array does not matter.

What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a complexity of O(1)? for(int i = 0; i < array.length; i++) for(int j = 0; j < array.length; j++) someMethod(array[j])

The complexity of this code is O(n2 ).

Let Dog be a subclass of Animal, and suppose Animal has a method called speak() that is overridden in the Dog class. Consider the following code. Animal spot = new Dog();spot.speak(); Which of the following is true?

The speak method defined in the Dog class will be called.

What does the following method compute? Assume the method is called initially with i = 0 public int question(String a, char b, int i){ if (i == a.length( )) return 0; else if (b == a.charAt(i)) return question(a, b, i+1) + 1; else return question(a, b, i+1); }

The number of times char b appears in String a

Write out the order of elements that are contained in a queue after the following operations are performed. myQueue.enqueue(new Integer(4)); myQueue.enqueue(new Integer(1)); Integer num = myQueue.dequeue(); myQueue.enqueue(new Integer(8)); myQueue.enqueue(new Integer(2)); myQueue.enqueue(new Integer(5)); myQueue.enqueue(new Integer(3)); Integer num = myQueue.dequeue(); myQueue.enqueue(new Integer(4));

The queue, after each operation (rear of queue at the left): 4 3 5 2 8 - front of the queue

. What is special about the Center in the BorderPane Layout

The specialty about the Center in the BorderPane Layout is that after setting Top, Bottom, Left, and Right of a BorderPane, Center takes all remaining spaces. If a particular position such as Bottom is not set, Center takes that space too

How is data given to its parameter?

Through a command line interface. For example: java someCompiledClass data

Consider the following classes: public class Vehicle {...} public class Car extends Vehicle {...} public class SUV extends Car {...} Which of the following are legal statements? There are more than one correct answer.

Vehicle v = new SUV(); SUV s = new SUV(); Car c = new SUV(); Vehicle v = new Car();

Write the output generated by the following program public class Mystery{ public static void writeStuff( int n ) { if( n == 0 ) System.out.print( n ); else { System.out.print( "[" ); writeStuff( n -1 ); System.out.print( "]" ); } } public static void moreStuff( int n, String s ) { if( n == 1 ) System.out.println( s + n ); else{ s = s + "+="; moreStuff( n -1, s ); } } public static void main(String[] args) { writeStuff( 1 ); System.out.println( ); writeStuff( 2 ); System.out.println( ); writeStuff( 3 ); System.out.println( ); moreStuff( 1, "One: " ); moreStuff( 2, "" ); moreStuff( 3, "Three: " ); }}

[0] [[0]] [[[0]]] One: 1 +=1 Three: +=+=1

Demonstrate how the following array is sorted using Merge Sort. Show the array after each recursive call (after merging). [44, 21, 13, 1]

[44,21,13,1] [44,21] [13,1] [44] [21] [13] [1] [1,13] [21,44] [1,13,21,44]

Perform the partition method of quick sort once on the array [5, 8, 1, 3 7, 9, 2]. Show the array after each iteration of the while loop in the partition method. Use the first element (here it is 5) as the pivot

[5,8,1,3,7,9,2] [8,1,3,5,7,9,2] [8,1,3,2,7,9,5] [2,1,3,8,7,9,5] [2,1,3,5,7,9,8] [2,1,3][5][7,9,8] [2,3,1][5][7,8,9] [1,3,2][5][7,8,9] [1,2,3][5][7,8,9] [1,2,3,5,7,8,9]

Perform the partition method of quick sort once on the array [8, 12, 2, 15, 7]. Show the array after each iteration of the while loop in the partition method. Use the first element (here it is 8) as the pivot. Show the two-sub array after one call to quick sort.

[8 ,12, 2, 15, 7] [7, 12, 2, 15, 8] [2,7,12,15,8] [7,2][8,12,15]

Trace the output of the following Stack code.importjava.util.*; public classStackTester { public static voidmain(String[]args){ Stack<String> mystack = newStack<String>(); mystack.push("Blue"); System.out.println(mystack.toString()); mystack.push("Red"); System.out.println(mystack.toString()); mystack.push("Green"); System.out.println(mystack.toString()); System.out.println(mystack.pop()); System.out.println(mystack.toString()); mystack.push("Orange"); mystack.push("Yellow"); System.out.println(mystack.toString()); System.out.println(mystack.peek()); System.out.println(mystack.toString()); mystack.pop(); mystack.pop(); mystack.pop(); System.out.println(mystack.toString()); }}

[Blue] [Blue, Red] [Blue, Red, Green] Green [Blue, Red] [Blue, Red, Orange, Yellow] Yellow [Blue, Red, Orange, Yellow] [Blue]

Trace the output of the following Linked List code, which uses an Iterator. import java.util.*; public class LinkedListTester { public static void main(String[] args) { LinkedList list = new LinkedList(); ListIterator iterator = list.listIterator(); iterator.add("Blue"); System.out.println(list.toString()); iterator.add("Red"); System.out.println(list.toString()); iterator.add("Green"); System.out.println(list.toString()); iterator = list.listIterator(); iterator.next(); iterator.add("Orange"); System.out.println(list.toString()); iterator = list.listIterator(); iterator.next(); iterator.remove(); System.out.println(list.toString()); } }

[Blue] [Blue, Red] [Blue, Red, Green] [Blue, Orange, Red, Green] [Orange, Red, Green]

Write the output generated by the following program import java.util.*; public class SomeObjects { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add("ab" ); list.add("cd" ); list.add("ef" ); System.out.println( list.toString( ) ); System.out.println(list.size( ) ); System.out.println(list.get( 1 ) ); } }

[ab, cd, ef] 3 cd

In a recursive solution, _______________ is(are) always necessary.

a base case

The idea of having programmers and developers meet in order to critique a software design or implementation is known as ____________

a walkthrough

Assume a sorted array numbers has the following values in position 0 through 12. 5,8,13,23,24,25,43,51,67,69,70,71,72. a)Using a binary search, what valuesare examined (list in order) to determine if 51is in the array? b)Using binary search, what valuesare examined (list in order) to determine if 6is in the array?

a. 43, 69, 51 b. 43, 13, 5, 8

Which of the following array declarations are invalid? int [] grades = new int[5]; int grades [] = new int[5]; int [] grades = {91,83,42,100,77};

all are valid

Which of the following methods must be implemented in a collection that implements the Iterator interface?

all of the methods (hasNext, next and remove)

A mouse event is generated by A mouse event is generated by pressing the mouse clicking the mouse button dragging the mouse double clicking the mouse button

all of them

In a UML diagram for a class: there may be a section containing the name of the class there may be a section containing the attributes (data) of the class there may be a section containing the methods of the class classes are represented as rectangles,

all of them

The main class for a JavaFX application extends the ____________ class

application

If you instantiate an object from an Abstract class, the object you wind up with

can't exist - you cannot instantiate an Abstract class

If you instantiate an object from an Abstract class, the object

can't exist - you cannot instantiate an object from an Abstract class

In Java, polymorphic method binding occurs:

at run time

Inheritance through an extended (derived) class supports which of the following concepts?

code reuse

Which of the following GUI components would you use to display a list of options so that the user could select between the entries in the list?

combobox

Which of the following is not a method of the Object class?

compareTo

Given two reference variables named objand str, write "Compiles" if the code will compile or "Error" if there will be a compile time error. Object obj = new Object( ); String str = new String( ); -a ____________ obj = str; -d _____________ int e = obj.length( ); -b ____________ str = obj; -e _____________ int f = str.length( ); -c _____________str = (String)obj; -f _____________ obj = "New String";

compiles - a,c,e,f error - b,d

Use the code below to answer the next question Note that the catch statements in the code are not implemented, but you will not need those details. Assume filename is a String, x is an int, a is a double array and i is an int. Use the comments i1, i2, i3, e1, e2, e3, e4, e5 to answer the questions (i for instruction, e for exception handler). An exception raised by the instruction in i1 would be caught by the catch statement labeled try { BufferedReader infile = new BufferedReader(new FileReader(filename)); // i1 int x = Integer.parseInt(infile.readLine( )); // i2 a[++i] = (double) (1 / x); // i3 } catch (FileNotFoundException ex) {...} // e1 catch (NumberFormatException ex) {...} // e2 catch (ArithmeticException ex) {...} // e3 catch (ArrayIndexOutOfBounds ex) {...} // e4 catch (IOException ex) {...} // e5

e1

If you have a Button object named "button1" and a listener named "ButtonOneListener", how do you associate the listener with "button1"?

button1.setOnAction(new ButtonOneListener());

In order to determine the type that a polymorphic variable refers to, the decision is made

by the Java run-time environment at run time

The instruction super( ); does which of the following

calls the constructor as defined in the current class' parent class

The instruction super( ); does which of the following?

calls the constructor as defined in the current class' parent class

Use the code below to answer this question. Note that the catch statements in the code are not implemented, but you will not need those details. Assume filename is a String, x is an int, a is a double array and i is an int. Use the comments i1, i2, i3, e1, e2, e3, e4, e5 to answer the questions (i for instruction, e for exception handler). try{ BufferedReader infile = new BufferedReader(new FileReader(filename));// i1 int x = Integer.parseInt(infile.readLine( )); // i2 a[++i] = (double) (1 / x); // i3} catch (NumberFormatException ex) {...} // e1 catch (ArrayIndexOutOfBounds ex) {...} // e2 catch (ArithmeticException ex) {...} // e3 catch (FileNotFoundException ex) {...} // e4 catch (IOException ex) {...} // e5 Question: An exception raised by the instruction in i3 would be caught by the catch statement labeled

either e2 or e3

Use the code below to answer the next question Note that the catch statements in the code are not implemented, but you will not need those details. Assume filename is a String, x is an int, a is a double array and i is an int. Use the comments i1, i2, i3, e1, e2, e3, e4, e5 to answer the questions (i for instruction, e for exception handler). An exception raised by the instruction in i2 would be caught by the catch statement labeled try { BufferedReader infile = new BufferedReader(new FileReader(filename)); // i1 int x = Integer.parseInt(infile.readLine( )); // i2 a[++i] = (double) (1 / x); // i3 } catch (FileNotFoundException ex) {...} // e1 catch (NumberFormatException ex) {...} // e2 catch (ArithmeticException ex) {...} // e3 catch (ArrayIndexOutOfBounds ex) {...} // e4 catch (IOException ex) {...} // e5

either e2 or e5

A(n) _____________________ is an object that defines an unusual or erroneous situation that is typically recoverable.

exception

Which of the following key words indicates a new class is being derived from an existing class?

extends

A TextArea can be used to display text, but not to edit text by the user.

false

All Java classes must contain a main method which is the first method executed when the Java class is called upon.

false

All parts of a BorderPane must be used.

false

In the following code object1 is the event handler object? Button object1 = new Button("Push Me!"); ButtonHandler object2 = new ButtonHandler(); private class ButtonHandler implements EventHandler<ActionEvent> { //Override the abstract method handle() public void handle(ActionEvent e) { //code to be completed } }

false

Java methods can return only primitive types (int, double, float, char, boolean, etc).

false

Question 220 / 2 pts The type of the reference, not the type of the object, is use to determine which version of a method is invoked in a polymorphic reference.

false

The Towers of Hanoi puzzle cannot be solved iteratively.

false

The most important decisions regarding the development of a system are made during the implementation phase while code is actively being written.

false

Write the output generated by the following code using the LinkedStack class. Stack aStack = new LinkedStack( ); aStack.push( "3" ); aStack.push( "2" ); aStack.push( "1" ); System.out.println( aStack.isEmpty( ) ); System.out.println( aStack.peek( ) ); aStack.pop(); System.out.println( aStack.peek( ) ); aStack.pop(); System.out.println( aStack.peek( ) ); aStack.pop(); System.out.println( aStack.isEmpty( ) );

false 1 2 3 true

In order to display three components (nodes) vertically in a pane, you could use all but which of the following layout managers given the size of the Pane is fixed.

flow

Which of the following layout managment organizes the nodes from left to right, starting new rows as necessary?

flowPane

Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

foo(0 / 1, 2 * 3);

Name two methods that class XYZ has that class Object does not. import java.util.ArrayList; public class XYZ extends ArrayList{}

get add size

You call the ___________________ method to determine what option is selected from a list of options available by a ComboBox

getValue

In general, spending more time in development and focusing on code reusing to ensure better software will

greatly reduce maintenance efforts

Which Layout Pane would you use if you want GUI components to be placed in 2 columns over 5 rows?

grid

Which Layout pane would you use if you want to add controls to be placed in 2 columns over 5 rows?

gridPane

What layout manager could you use to place components in 4 columns over 7 rows?

gridpane

Assume that head references a linked list that stores the values 3, 6 and 2. Show the instructions needed to delete the Node with 3 from the list so that head would reference the list of 6 and 2.

head = head.next;

A java application always contains a single method, what is the method name and give the signature of this method.

main publicstaticvoidmain(String[] args)

A class' constructor usually defines

how an object is initialized

In order to create a class that implements an interface, the __________________ keyword is usedc

implements

__________________ recursion results from the lack of a base case.

infinite

Which of the following algorithms has a worst-case complexity of O(n2 )?

insertion sort selection sort bubble sort

Assume that head references a linked list although we don't know what is currently stored in that list. Write a block of code using a try-catch block that will work through the entire linked list printing each element out, stopping only when we have reached the end of the list because a NullPointerException is thrown. Once the Exception is thrown, output the number of elements found in the list

int count = 0; try { Node temp = head; while (true) { System.out.println(temp.info); temp = temp.next; count++; } } catch (NullPointerException npe) { System.out.println("Number of elements in the list is " + count); }

Abstract methods are used when defining

interface

In Java, a(n) ___________________ is a collection of constants and abstract methods

interface

What is Encapsulation?

is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. ... Declare the variables of a class as private. Provide public setter and getter methods to modify and view the variables values

What is printed by the following code? public class Inherit{ abstract class Speaker { abstract public void speak( ); } class Cat extends Speaker { public void speak( ){ System.out.print("Woof! "); }} class Dog extends Speaker{ public void speak( ) { System.out.print("Meow! "); }} Inherit( ) { Speaker d = new Dog( ); Speaker c = new Cat( ); d.speak( ); c.speak( ); } public static void main(String[ ] args){ new Inherit( ); }}

meow! woof!

Having multiple class methods of the same name where each method has a different number of or type of parameters is known as

method overloading

Which of the following reserved words in Java is used to create an instance of a class?

new

Which of the following methods are included with any object that implements the Iterator interface?

next and hasNext

Which of the following nodes (control) allows the user to enter typed input from the keyboard. check boxes radio buttons combo boxes sliders

none

For next question, assume that Student, Employee and Retired are all extended classes of Person, and all four classes have different implementations of the method getMoney. Consider the following code where ... are the required parameters for the constructors: Person p = new Person(...); int m1 = p.getMoney( ); // assignment 1 p = new Student(...); int m2 = p.getMoney( ); // assignment 2 if (m2 < 100000) p = new Employee(...); else if (m1 > 50000) p = new Retired(...); int m3 = p.getMoney( ); // assignment 3 The reference to getMoney( ) in assignment 3 is to the class

none of the options, this cannot be determined by examining the code

All classes in Java are directly or indirectly subclasses of the _______ class.

object

The relationship between a class and an object is best described as

objects are instances of classes

One operation that we might want to implement on a Stack and a Queue is full, which determines if the data structure has room for another item to be added. This operation would be useful

only if the Queue or Stack is implemented using an array

Polymorphism is achieved by _____

overriding

Which of the following will result from infinite recursion in Java?

program will run out of memory

In a UML diagram the # sign means_______.

protected

Complete the class makes this code valid and generated the output shown in comments. MyClass a = new MyClass( ); MyClass b = new MyClass( 100 ); System.out.println( a.getValue( ) ); // -1 System.out.println( b.getValue( ) ); // 100 public class MyClass{private int value;//Constructors public int getValue( ){ return value; }}

public MyClass() { value = -1; } public MyClass(int value) { this.value = value; }

Consider the following class definition: public class AClass{ protected int x; protected int y; public AClass(int a, int b){ x = a; y = b; } public int addEm( ){ return x + y; } public void changeEm( ){ x++;y--; } public String toString( ){ return " " + x + " " + y; }} Write the BClass with the following specifications: •BClass extends the AClass •BClass will have a third int instance data, z. •A constructor for the BClass. •Override method addEm to add all three values and return the sum. •Override the toString method for theBClass Note: The best way to redefine a method is to reuse the parent class' method and supplement it with the code needed to handle the changes in the subclass

public class BClass extend AClass{ private int z; public BClass(int a, int b, int c){ super(a,b); z = c; } public int addEm( ){ return super.addEm() + z; } public String toString( ){ return super.toString() + " " + z; }}

Now write a Java class called Box. A box has a Rectangle and a height. (this is called aggregation)Implement a constructor that takes the Rectangle object and the height of the box.Also implement the following methods: getHeight(),setHeight(int), getLength(), setLength(int), getWidth(),setWidth(int ), method area(), and method volume().

public class Box{ private int height; private Rectangle rect; public Box(){ height = 0; Rect = new Rectangle() } public Box(Rectangle rect, int height){ this.rect = rect; this.height = height; } public int getHeight(){ return height; } public void setHeight(int height){ this.height = height; } public int getLength(){ return rect.getLength(); } public void setLength(int length){ rect.setLength(length); } public int getWidth(){ return rect.getWidth(); } public void setWidth(int width){ rect.setWidth(width); } public int area(){ return (2 * rect.area()) + (2 * rect.getLength() * height) \+ (2 * rect.getWidth() * height); } public int volume(){ return rect.area() * height; } }

To define a class that will represent a car, which of the following definitions is most appropriate?

public class Car

Write a Java class named Histogramthat allows for a visual peek at quiz scores where "*" means 1 out of 10 on a quiz. If a quiz score (the integer arguments in addAndShowOne) is outside the valid range of 0 through 10, the method addAndShowOnemust print the argument followed by the string "is out of range". If the quiz score argument is in range, print the quiz score after the correct number of *'s. For example, if the quiz score argument is 8, print ********followed by 8. You should be able to ask the Histogramobject for the average quiz score at any time with a method named getAverage(see the last line of output).

public class Histogram { private double sum; private int n; public Histogram( ) { sum = 0.0; n=0; } public void addAndShowOne( int score ) { if( score < 0 || score > 10 ) System.out.println( score + " is out of range" ); else { for( int j = 1; j <= score; j++ ) System.out.print( "*" ); System.out.println( " " + score ); n++; sum+=score; } } public double getAverage( ) { return sum / n; }}

a linked list that stores int values would be compromised of a group of nodes. we might define the node by

public class Node { int data; Node next; }

Write a Java class named Rectangle. A rectangle object has length and width. Writethedefault constructor and the constructor that takes the length and width of the rectangle. Also write accessor and mutator methods for your Rectangle class: getLength(), getWidth, setLength(int), setWidth(int).Implement the method areawhich computes the area of the rectangle.

public class Rectangle{ private int length; private int width; public Rectangle(int length, int width){ this.length = length; this.width = width; } public int getLength(){ return length; } public int getWidth(){ return width; } public void setLength(int length){ this.length = length; } public void setWidth(int width){ this.width = width; }public int area(){ return length * width; }}

Circle method signatures which will cause an error if allmethods were defined in a single class? public int calc(int num1, int num2){ ... } public double calc(int num1, int num2){ ...} public int calc(double num1, int num2){ ... } public int calc(int num3, int num4){ ... } public int calc(int num1, int num2, int num3){ ... }

public int calc(int num1, int num2){....} public double calc(int num1, int num2){.....} public int calc(int num3, int num4){....}

Which of the following methods could be used to sum all of the items in the linked list? Assume sum =0; and temp = head when the method is called.

public int sumIt(Node temp) { while (temp != null){ sum += temp.info; temp = temp.next; } return sum; }

Rewrite the following iterative method as a recursive method that computes the same thing. NOTE: your recursive method will require an extra parameter. Do not use static variables. Show how your recursive method can be called from a main method by specifying the value of all parameters for the recursive method. public static int compute(int[] num, int k) { int count = 0; for (int j=0; j<num.length; j++) { if(num[j] ==k){ num[j]+=2; count++; }} return count; }

public static int compute2(int[] num, int k, int i) { if (i == 0){ if (num[i] == k) { num[i] +=2; return 1; } else return 0; } else{ if (num[i] == k){ num[i] += 2; return (1+compute2(num, k, i-1)); } else return compute2(num, k, i-1); } } From a main method: int[] num = { 3, 2, 4, 3, 5, 1, 2, 3, -1, 6}; //2nd parameter can be any integer int ans = compute2(num, 3, num.length-1);

Using recursion, complete method goingUpso it displays all the numbers from the first argument to the last in ascending order (separate with a space). You can NOT use a loop. What is the base case? When should the method call itself (recursive case)? public class TestGoingUp{ public static void goingUp( int start, int stop ) { } public static void main(String[] args) { goingUp( 1, 5 ); System.out.println( ); goingUp( 2, 7 ); System.out.println( ); goingUp( 3, 3 ); System.out.println( ); }}

public static void goingUp( int start, int stop ) { if( start == stop ) System.out.print( start + " " ); else{ System.out.print( start + " " ); goingUp( start + 1, stop ); }}

Write recursive method reverseArraythat reverses the elements in an array of ints. The program below must generate the output shown in the box. reverseArraycan not use a loop. public class TestReverse{ public static void show( int[] x, int n ){ System.out.print( "[ " ); for(int j = 0; j < n; j++ ) System.out.print( x[j] + " " ); System.out.println( "]" ); } public static void main(String[] args){ int[] x = { 1, 2, 3, 4, 5, 6, 7, 8 }; show( x, x.length ); reverseArray( x, 0, x.length-1 ); show( x, x.length ); }} Output should be [ 1 2 3 4 5 6 7 8 ] [ 8 7 6 5 4 3 2 1 ]

public static void reverseArray( int[] x, int first, int last ){ if( first < last ){ // Do nothing if last >= first empty array or one with one element swap( x, first, last ); reverseArray( x, first + 1, last -1 ); }} public static void swap( int[] x, int first, int last ){ int temp = x[first]; x[first] = x[last]; x[last] = temp; }

Which method must be implemented if a class implements EventHandler interface?

public void handle(ActionEvent e)

One use of a Stack is to reverse the order of input. Write a method that reads a series of Strings from the keyboard (assume the Scanner class has been imported) and outputs the Strings in reverse order of how they were entered. The input will end with the String "end" but do not output the String "end". Assume that SStack is a Stack that can store Strings. Remember to declare and instantiate your SStack in your method.

public void reverseOrder( ) { SStack s = new SStack( ); Scanner scanner = new Scanner(System.in); String in = scanner.next( ); while (!in.equals("end")) { s.push(in); in = scanner.next( ); } while (!s.empty( )) { System.out.println(s.pop( )); } }

Write a recursive method void sumReverse(intn)that when given an integer n > 0, prints the integer expression (with addition operator). For example, if n is 4, your method would print: 4 + 3 + 2 + 1 (After finishing this, tryto write a method that prints1 + 2 + 3 + 4 at home)

public void sumReverse(int n) { if (n == 1) System.out.println(n); else{ System.out.print(n + " + "); sumReverse(n-1); //print (n-1) + (n-2) + ... + 2 + 1 }}

If you have the following code, how do you associate the listener with push button? Button push = new Button("Push Me!"); private class ButtonHandler implements EventHandler<ActionEvent> { //Override the abstract method handle() public void handle(ActionEvent e) { //code to be completed } }

push.setOnAction(new ButtonHandler());

Name two methods other than the default constructor that the Extension class currently has. public class Extension {}

toString , equals

In order to gain a last-in first-out access to data, which type of structure should be used?

stack

What are the three top-level, fundamental components of JavaFX application?

stage, scene, nodes

What is wrong with the following recursive sum method? The method is supposed to sum up the values between 1 and x (for instance, sum(5) should be 5 + 4 + 3 + 2 + 1 = 15). public int sum(int x){ if (x == 0) return 0; else return sum(x - 1) + x; }

the base case condition should be (x <= 0) instead of (x = = 0)

A bad programming habit is to build an initial program and then spend a great deal of time modifying the code until it is acceptable. This is known as

the build-and- fix approach

What does the following method compute? Assume the method is called initially with i = 0 public int question(String a, char b, int i){ if (i = = a.length( )) return 0; else if (b = = a.charAt(i)) return question(a, b, i+1) + 1; else return question(a, b, i+1); }

the number of times char b appears in String a

An object that refers to part of itself within its own methods can use which of the following reserved words to denote this relationship?

this

Assume Exceptionname is a checked exception. If a method uses a class that can generate Exceptionname, then either the method must include try and catch statements where a catch statement catches Exceptionname, or the method header must include the statement

throws Exceptionname

Which of the following methods are included in every class created in Java by inheritance?

toString

A combo box allows the user to select one of several options from a "drop down" menu.

true

A polymorphic reference can refer to different types of objects over time.

true

A simple JavaFX program executes on a stage, which represents the window in which the application runs.

true

An array, when instantiated, is fixed in size, but an ArrayList can dynamically change in size when new elements are added to it.

true

Arrays are passed as parameters to methods like object types.

true

In white-box testing, the tester should already know something about how the program is implemented so that he/she can more carefully identify what portion(s) of the software are leading to errors.

true

Let Animal be an interface. Then it is possible to create an object by instantiating the Animal interface

true

Queues and Stacks can be implemented using either arrays or linked lists.

true

Solutions that are easily expressed recursively should be programmed recursively.

true

The term "test case" is used to express a set of inputs (or user actions) and the expected outputs to be used in testing out software

true

You do not have to call the handle method since the FX library calls the

true

You do not have to call the handle method since the FX library calls the method automatically, for example when a button is clicked.

true

A(n) ____________________ is used to identify a block of statements that may cause an exception.

try block

Trace the output of the following code using the LinkedList and ListIterator class we discussed in class. public class LinkedListTester { public static void main(String[] args) { LinkedList list1 = new LinkedList(); ListIterator iterator = list1.listIterator(); iterator.add("Apple"); printList(list1); iterator.add("Orange"); printList(list1); iterator.add("Tomato"); printList(list1); iterator = list1.listIterator(); iterator.next(); iterator.next(); iterator.add("Banana"); printList(list1); iterator.next(); iterator.add("Lemon"); printList(list1); iterator = list1.listIterator(); iterator.next(); iterator.remove(); while (iterator.hasNext()) System.out.println(iterator.next()); } //This method prints out the content of LinkedList public static void printList(LinkedList list1) { ListIterator iterator = list1.listIterator(); String result = "{ "; while (iterator.hasNext()) result += iterator.next() + " "; result += "}"; System.out.println(result); } }

{ Apple } { Apple Orange } { Apple Orange Tomato } { Apple Orange Banana Tomato } { Apple Orange Banana Tomato Lemon } Orange Banana Tomato Lemon


Ensembles d'études connexes

COM 1100 Chapter 11 Review Questions

View Set

ECON 320 - Ch.4: Monetary System HW

View Set

Sec Plus Lesson 2 Comparing and Contrasting Security Controls

View Set

PrepU Chapter 40: Nursing Care of the Child With an Alteration in Gas Exchange/Respiratory Disorder

View Set

Estructura de las palabras. Los monemas (teoría)

View Set