Question
URGENT!!!!!!!!!!!! 1. How many private instance variables does this class have? Refer to the following UML Class Diagram when answering this question. Pet - name
URGENT!!!!!!!!!!!!
1. How many private instance variables does this class have?
Refer to the following UML Class Diagram when answering this question.
Pet |
- name : int + age : String + hasFleas : Boolean - licenseNumber : String - weight : float - color : String |
- Pet() + Pet(name : String, age : int) + getName() : String + setName(name : String) : void - getAge() : int - setAge(age : int) : void + speak() : void + scratch(itches : int) : void + toString() : String |
2. The Java keyword throw is used to catch an exception.
True
False
3. Evaluate the following code to determine what value will be at the top of the stack after the code completes.
MyStacks = new MyStack (); s.push(35); s.push(53); s.push(99);
4. Evaluate the following code to determine the output.
MyQueueq = new MyQueue (); q.add(14); q.add(45); q.add(83); q.remove();q.remove(); System.out.println(q.remove());
5. Given the following partial code, fill in the blank to complete the code necessary to remove the second node. (don't forget the semicolon)
... class Node { public Object data = null; public Node next = null; } ... Node head = new Node(); // first Node head.next = new Node(); // second Node head.next.next = new Node(); // third node head.next.next.next = new Node(); // fourth node _____________________ //
6. Given the following partial code, fill in the blank to complete the code necessary to insert node xin between the first two nodes. (don't forget the semicolon)
... class Node { public Object data = null; public Node next = null; } ... Node head = new Node(); // first Node head.next = new Node(); // second Node head.next.next = new Node(); // third node Node x = new Node(); // node to insert x.next = head.next; // _____________________ //
7. Given that:
int[] list = {3,7,12,17,23,28,32,39,43,49,53,59,63,68,72};
and:
int targetValue = 42;
and given this Binary Search algorithm:
public static int BinarySearch(int[] list, int targetValue) { int mid, low, high; low = 0; high = list.length - 1; while (high >= low) { mid = (high + low) / 2; if (list[mid] < targetValue) { low = mid + 1; } else if (list[mid] > targetValue) { high = mid - 1; } else { return mid; } } return -1; // not found }
Which value in list will be the third to be compared to the targetValue in a binary search for the target value?
8. Given the following sorting algorithm:
01 public static void selectionSort(int [ ] numbers) { 02 int i, j, temp; 03 int indexSmallest; 04 05 for (i = 0; i < numbers.length - 1; i++) { 06 07 // Find index of smallest remaining element 08 indexSmallest = i; 09 for (j = i + 1; j < numbers.length; j++) { 10 11 if (numbers[ j ] < numbers[ indexSmallest ]) { 12 indexSmallest = j; 13 } 14 } 15 16 // Swap numbers[ i ] and numbers[ indexSmallest ] 17 temp = numbers[ i ]; 18 numbers[ i ] = numbers[ indexSmallest ]; 19 numbers[ indexSmallest ] = temp; 20 } 21 }
and applying it to the following list:
int[ ] numbers = {87, 43, 54, 6, 21, 67};
What value will be at index 2 in numbers after line# 19 executes 4 time(s)?
9. Given the following sorting algorithm:
01 public static void insertionSort(int [] numbers) { 02 int i, j, temp; 03 04 for (i = 1; i < numbers.length; ++i) { 05 j = i; 06 // Insert numbers1 into sorted part 07 // stopping once numbers1 in correct position 08 while (j > 0 && numbers[j] < numbers[j - 1]) { 09 10 // Swap numbers[j] and numbers[j - 1] 11 temp = numbers[j]; 12 numbers[j] = numbers[j - 1]; 13 numbers[j - 1] = temp; 14 --j; 15 } 16 } 17 }
and applying it to the following list:
int[ ] numbers = {81, 39, 62, 13, 31, 68};
What value will be at index 1 in numbers after the while loop (on lines 08 - 15) finishes 2 time(s)?
10. In a Binary Search Tree, all elements below a given a node have values that are > that node's value.
Group of answer choices
True
False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started