Java assignments needed to get done, would like a quote, I can send a sample assignment once contacted

profilejzhng1
homework.docx

Consider this code using the ArrayBag of Section 5.2 and the Location class from Chapter 2. What is the output?

Location i = new Location(0, 3);

Location j = new Location(0, 3);

b.add(i);

b.add(j);

System.out.println(b.countOccurrences(i));

A. 0

B. 1

C. 2

D. 3

Suppose that b and c are Integer objects. A typical use of the clone method looks like this:

b = (Integer) c.clone( );

Write a short clear explanation of why the (Integer) type cast is required in this typical example.

A. obj = s;

B. s = obj;

C. s = (String) obj;

D. Two or more answers are correct.

Suppose that obj is an Object variable and s is a String variable. Which of the following statements

is a correctly-compiling widening conversion? Don't worry about possible run-time exceptions

A. obj = s;

B. s = obj;

C. s = (String) obj;

D. Two or more answers are correct.

Suppose that x and y are reference variables and a program activates x.equals(y). What occurs if x is the null reference?

A. A NullPointerException occurs

B. It always returns true.

C. It always returns false.

D. It returns true if y is also a null reference; otherwise it returns false.

Consider the implementation of the Stack using a partially-filled array.

What goes wrong if we try to store the top of the Stack at location [0] and the bottom of the Stack at the last used position of the array?

A. Both peek and pop would require linear time.

B. Both push and pop would require linear time.

C. The Stack could not be used to check balanced parentheses.

D. The Stack could not be used to evaluate postfix expressions.

Write some lines of code that declares an Integer object, using the Integer wrapper class.

Assign the value 42 to this object, then copy this value from the Integer object to an ordinary int variable.

Consider the usual algorithm for determining whether a sequence of parentheses is balanced.

What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?

A. 1

B. 2

C. 3

D. 4

E. 5 or more

Consider the usual algorithm to convert an infix expression to a postfix expression.

Suppose that you have read 10 input characters during a conversion and that the

stack now contains the symbols as shown below. Suppose that you read and process

the 11th symbol of the input. What symbol is at the top of the stack in the case where

the 11th symbol is each of the choices shown?

Which of the following stack operations could result in stack underflow?

Answer

A. is_empty

B. pop

C. push

D. Two or more of the above answers

What is the value of the postfix expression 6 3 2 4 + - *:

Answer

A. Something between -15 and -100

B. Something between -5 and -15

C. Something between 5 and -5

D. Something between 5 and 15

E. Something between 15 and 100

1. An array of queues can be used to implement a priority queue, with each possible priority corresponding to its own element in the array. When is this implementation not feasible?

Answer

A.

When the number of possible priorities is huge. 

B.

When the number of possible priorities is small. 

C.

When the queues are implemented using a linked list. 

D.

When the queues are implemented with circular arrays.

Consider the implementation of the Queue using a circular array. What goes wrong if we try to keep all the items at the front of a partially-filled array (so that data[0] is always the front).

Answer

A.

The constructor would require linear time. 

B.

The getFront method would require linear time. 

C.

The insert method would require linear time. 

D.

The isEmpty method would require linear time.

If data is a circular array of CAPACITY elements, and rear is an index into that array, what is the formula for the index after rear?

Answer

A. (rear % 1) + CAPACITY

B. rear % (1 + CAPACITY)

C. (rear + 1) % CAPACITY

D. rear + (1 % CAPACITY)

In the linked-list version of the Queue class, which operations require linear time for their worst-case behavior?

Answer

A. getFront

B. insert

C. isEmpty

D. None of these operations require linear time.

Which of the following expressions evaluates to true with approximate probability equal to P? (P is double and 0 <= P <= 1).

Answer

A. Math.random() < P

B. Math.random() > P

C. Math.random() < P * 100

D. Math.random() > P * 100

Consider the following method:  public static void test_a(int n) {    System.out.println(n + " ");    if (n>0)    test_a(n-2); } What is printed by the call test_a(4)?

A. 0 2 4

B. 0 2

C. 2 4

D. 4 2

E. 4 2 0

Consider the following method:  public static boolean deadend() // Postcondition: The return value is true if the direction directly // in front is a dead end (i.e., a direction that cannot contain the // tapestry). {   return inquire("Are you facing a wall?") || inquire("Is your name written in front of you?"); } Explain why the method deadend sometimes asks 2 questions and sometimes asks only 1.

Consider the following method:

void superWriteVertical(int number)

// Postcondition: The digits of the number have been written,

// stacked vertically. If number is negative, then a negative

// sign appears on top.

{

if (number < 0)

{

System.out.println("-");

superWriteVertical(-number);

}

else if (number < 10)

System.out.println(number);

else

{

superWriteVertical(number / 10);

System.out.println(number % 10);

}

}

What values of number are directly handled by the stopping case?

Suppose you are exploring a rectangular maze containing 10 rows and 20 columns. What is the maximum depth of recursion that can result if you start at the entrance and call traverse_maze?

What property of fractals lends itself to recursive thinking?

When the compiler compiles your program, how is a recursive call treated differently than a non-recursive method call?