Home / Questions / Which of the following would be correct declarations for a default constructor?...
Question 1
Problems 1 – 3 refer to the following class meant to represent the spinner in a board game:
class Spinner { private int numOptions; private int chosen; public Spinner (int n) { if (n >= 2 && n } spin (); } public void spin () { chosen = (int)(Math.random () * numOptions) + 1; } }
Consider the following code:
Spinner s = new Spinner(17); System.out.println(s);
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?
An equals method must be added.A toString method must be added.The variable chosen must be declared as private.The variable chosen must be declared as public.A mutator for the variable method for chosen must be added.Flag this QuestionQuestion 21 pts
Which of the following would be correct declarations for a default constructor?
I.
public Spinner() { this(2); }
II.
public Spinner() { numOptions = n; }
III.
public Spinner() { numOptions = 2; spin (); } II onlyI, II and IIIIII onlyI onlyI and III onlyFlag this QuestionQuestion 31 ptsWhich of the following is a correct declaration for a Spinner object as written?Spinner s = new Spinner(15);
Spinner = s;
new Spinner s = Spinner(15);
Spinner s = Spinner (15);
Spinner s = 20;
Flag this QuestionQuestion 41 ptsWhich of the following is true about classes and objects?A class is an instance of an object.Classes have a reference pointing to their location in memory.Objects have a reference pointing to their location in memory.It is possible to have many classes of the same object.Objects can be declared abstract.Flag this QuestionQuestion 51 pts
Consider the following class declarations:
public abstract class Thing { private int x; public abstract void one(); public void two () { /* Code not shown */ } /* Code not shown */ } public class Item extends Thing { /* Code not shown */ }
To instantiate an object of type Item which of the following must be true?
Item must contain a method named one.Item must contain a method named two.Item must contain a variable named x.The variable x in Thing should be declared abstract.The method two in Thing should be declared abstract.Flag this QuestionQuestion 61 pts
Consider the following code:
String vocabulary[] = new String [50];
The index of the first value is ______ and the last index is ______.
1 49
0 49
1 51
1 50
0 50
Flag this QuestionQuestion 71 pts
Consider the following code:
int[] a = {64 , 66 , 67 , 37 , 73 , 70 , 95 , 52 , 81 , 82}; for(int i =0; i for(int i =0; i
What is output?
4 6 7 7 3 0 5 2 1 26 6 6 3 7 7 9 5 8 85 7 8 8 4 1 6 3 2 37 7 7 4 8 8 10 6 9 92 4 5 2 2 8 6 8 1 2Flag this QuestionQuestion 81 ptsWhen using ______ search, the array does not need to be ordered.mergeinsertionselectionlinearbinaryFlag this QuestionQuestion 91 ptsWhich of the following is NOT true about ArrayList objects?They can be resized.Methods for insertion and deletion are built into the class.ArrayList is a class data type.ArrayList can only hold one data type.ArrayList can hold many data types at once.Flag this QuestionQuestion 101 ptsWhich of the following implements the Comparable interface?MathObjectListStringArrayListFlag this QuestionQuestion 111 pts
Consider the following code segment:
ArrayList list = new ArrayList (); list.add ("Cookies"); list.add ("nachos"); list.add ("chips"); list.add ("Trail mix"); list.add ("Celery"); for (String s: list) { if (s.toUpperCase().charAt(0) == s.charAt(0)) { System.out.print(s +" "); } }
What is printed as a result of executing the code segment?
Cookies chips CeleryNothing is printednachos chipsCookies Trail mix CeleryCookies nachos chips Trail mix CeleryFlag this QuestionQuestion 121 pts
What is output by the following code segment? Assume a Time class exists.
Time appointment1 = new Time(5, 45); Time appointment2 = new Time(5, 45); if (appointment1 == appointment2) { System.out.print("equal"); } else { System.out.print("not equal"); } Nothing, there is an errornot equalequalequalnot equalnot equalequalFlag this QuestionQuestion 131 pts
Consider the following method intended to swap the first and last rows in a two-dimensional array:
public static void swapRow (int[][] a) { /* missing code */ }
Which of the following correctly replaces /* missing code */
?
for (int k = 0; k for (int k = 0; k None of the answers listed. for (int k = 0; k for (int k = 0; k Flag this QuestionQuestion 141 pts
Consider the following method declaration.
public static void increment(int[][] a) { for (int r = 0; r < a.length; r++) { for (int c = 0; c < a[0].length; c++) { if (a[r][c] >= 0) { a[r][c]++; } else { a[r][c]--; } } } }
Assume the 2D array, matrix, has been initialized to the following values:
4 6 -15 5 11 21 -11 -10 3 4 -10 -18 -21 14 -23
What is the value of matrix after the method call, increment(matrix);
?
4 6 -16 5 11 21 -12 -11 3 4 -11 -19 -22 14 -24 5 7 -16 6 12 22 -12 -11 4 5 -11 -19 -22 15 -24 5 7 -14 6 12 22 -10 -9 4 5 -9 -17 -20 15 -22 4 6 -15 5 11 21 -11 -10 3 4 -10 -18 -21 14 -23 5 7 -15 6 12 22 -11 -10 4 5 -10 -18 -21 15 -23 Flag this QuestionQuestion 151 pts
Consider the following code.
int[][] matrix = new int[4][5];
Suppose we want to initialize matrix to the following rows and columns.
0 1 2 3 4 4 3 2 1 0 0 1 2 3 4 4 3 2 1 0
Which of the options below correctly initializes matrix?
I.
for (int i = 0; i
II.
for (int i = 0; i
III.
for (int i = 0; i I onlyII onlyII and III onlyI, II and IIIIII onlyFlag this QuestionQuestion 161 pts
Consider the following code:
int[][] grid = /* code not shown */;
Which of the following could be used to calculate how many cells are in the array?
grid.length * grid[0].length
grid[0].length
grid.length[0] * grid[0].length
grid.length
grid.length * grid.length
Flag this QuestionQuestion 171 pts
Consider the following declaration for a two-dimensional array.
int[][] grid = new int[3][5]; int c = 0; for (int i = 0; i
What element is displayed when the following line of code is executed?
System.out.println(grid[2][1]); 71112106Flag this QuestionQuestion 181 pts
What does the following segment of code do?
int[][] a = /* initialization not shown */; int sum = 0; for(int i = 0; i } } } It finds the sum of the even elements in the array.It finds the sum of every other element in the array.It finds the sum of all elements in the array.It finds the sum of the elements in the even rows in the array.It finds the sum of the elements in the even columns in the array.Flag this QuestionQuestion 191 pts
Which option best describes what the following algorithm does?
int a [][] = /* initialization not shown */; int j = 2; for (int i = 0; i Swaps columns with index 2 and 3.Swaps columns with index 1 and 2.Swaps rows with index 2 and 3.Swaps rows with index 1 and 2.Initializes the values in the array.Flag this QuestionQuestion 201 pts
You need a method to find the maximum value in every row of an array. Which of the following methods works as intended?
I.
public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j = 0; j < a[0].length; j++) { if (a[i][j] > max) { max = a[0][j]; } } temp [i] = max; } return temp; }
II.
public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j =0; j < a[0].length; j++) { if (a[i][j] > max) { max = a[i][j]; } } temp [i] = max; } return temp; }
III.
public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j = 0; j < a[0].length; j++) { if(a[i][j] > a[0][j]) { max = a[i][j]; } } temp [i] = max; } return temp; } I, II and IIIII onlyIII onlyII and III onlyI only
Jul 06 2020 Read more Less More
Describe the function of proton pumps in root cells to facilitate transport of cations (such as K+),and anions (such asNO3-) across plant membranes and tell how this proc...
Apr 15 2020From the ledger balances given below, prepare a trial balance for the Marigold Corp. at June 30, 2019. All account balances are normal. Accounts Payable $9,450, Cash $...
Sep 22 2020Output from a software package follows:One-Sample Z:Test of mu = 20 vs > 20The assumed standard deviation = 0.75Variable = xN = 10Mean = 19.889StDev = ?SE Mean = 0.237Z =...
Apr 11 2020A telemarketing firm is monitoring the performance of its employees based on the number of sales per hour. One employee had the following sales for the last 20 hours.(Use...
Apr 23 2020John has been promoted from his hourly position to supervisor. John is having a difficult time dealing with the people problems his new position entails. It would be a ...
Dec 13 2019Based on the output shown in Figure 10.5, how long should it take a motor grader to grade a 10,000 square- foot area when the output is expected to be at the low end of t...
Jul 10 2020At a break-even point of 920 units sold, White Corporation's variable expenses are $9,200 and its fixed expenses are $2,760. What will the Corporation's net operating inc...
Apr 13 2020_____ provides a way for marketers to evaluate the effectiveness of the message and tailor their responses accordingly. a. Feedback b. The message c. The AIDA concept d. Noise
Sep 06 2020Great Harvest Bakery purchased bread ovens from New Morning Bakery. New Morning Bakery was closing its bakery business and sold its two-year-old ovens at a discount for $...
Aug 24 2020Which of these ratios indicate the firmâs ability to use its assets to an increase in sales: (Points : 3)Profitability ratios market value ratios Liquidity ratios Fi...
Sep 07 2020Welcome to MyCourseHelp Services, World's leading Academic solutions provider with Millions of Happy Students.