Problems 1 – 3 refer to the following class meant to represent the spinner in a
ID: 3738691 • Letter: P
Question
Problems 1 – 3 refer to the following class meant to represent the spinner in a board game:
Consider the following code:
The intention is for this code to print the value stored in chosen. For this to work correctly which of the following must be true?
The variable chosen must be declared as public.
Which of the following would be correct declarations for a default constructor?
I.
II.
III.
Which of the following is a correct declaration for a Spinner object as written?
Spinner = s;
Consider the following class declarations:
To instantiate an object of type Item which of the following must be true?
Item must contain a method named one.
Which of the following implements the Comparable interface?
ArrayList
Consider the following method intended to swap the first and last rows in a two-dimensional array:
Which of the following correctly replaces /* missing code */?
Consider the following method intended to swap the first and last rows in a two-dimensional array:
Which of the following correctly replaces /* missing code */?
Consider the following method declaration.
Assume the 2D array, matrix, has been initialized to the following values:
What is the value of matrix after the method call, increment(matrix);?
Consider the following code.
Suppose we want to initialize matrix to the following rows and columns.
Which of the options below correctly initializes matrix?
I.
II.
III.
III only
Consider the following code:
Which of the following could be used to calculate how many cells are in the array?
grid.length
Consider the following declaration for a two-dimensional array.
What element is displayed when the following line of code is executed?
12
What does the following segment of code do?
It finds the sum of the even elements in the array.
Which option best describes what the following algorithm does?
Swaps rows 2 and 3.
You need a method to find the maximum value in every row of an array. Which of the following methods works as intended?
I.
II.
III.
The variable chosen must be declared as private.Explanation / Answer
Question1:
A toString method must be added.
Question2:
I and III only
Question3:
Spinner s = new Spinner(15); // argument constructor is defined
Question4:
Objects have a reference pointing to their location in memory.
Question5:
Item must contain a method named one. ( method one is abstract in base class ,should be implemented in derived class)
Question6:
0 49 ( arrays starts from index 0)
Question7:
6 6 6 3 7 7 9 5 8 8 (integer division)
Question8:
linear? ( does not need sorted list)
Question9:
ArrayList can hold many data types at once.
Question10:
Object
Question11:
Cookies Trail mix Celery(first character is uppercase)
Question12:
not equal (equals method not defined)
Question13: swap rows
for (int k = 0; k < a[0].length; k++)
{ int last = a.length - 1; int temp = a [0][k]; a[0][k] = a[last][k]; a[last][k] = temp; }
Question14:
5 7 -16 6 12 22 -12 -11 4 5 -11 -19 -22 15 -24 ?(greater than 0 , increment else decrement)
Question15:
I, II and III
Question16:
grid.length*grid[0].length
Question17:
11
Question18:
It finds the sum of the even elements in the array.( even elements are divisible by 2 , i%2 == 0)
Question19:
Swaps rows 2 and 3.
Question20:
II only
Do ask if any doubt. Please upvote.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.