Question 15 of 30 (worth 3 points) Which of the following would be a correct way
ID: 3771168 • Letter: Q
Question
Question 15 of 30 (worth 3 points)
Which of the following would be a correct way to call (invoke) this method?
public static void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
printArray({3, 1, 2, 6, 4, 2});
printArray(int[]);
printArray(int[] result);
int[] result={3, 1, 2, 6, 4, 2};
printArray(result);
Question 16 of 30 (worth 3 points)
Pick all that apply:
java.util.Arrays class contains which of the following methods?
Check to review before finishing (will be flagged in Table of Contents)
Question 18 of 30 (worth 3 points)
Consider the following class:
public class Bicycle {
private int cadence;
private int gear;
private int speed;
private int id;
private static int numberOfBicycles = 0;
public Bicycle(int startCadence, int startSpeed, int startGear){
gear = startGear;
cadence = startCadence;
speed = startSpeed;
id = ++numberOfBicycles;
}
public int getVar() {
//TODO return a variable
}
public static int getVariable() {
//TODO return a variable
}
}
Which of the following return statements should be used in the getVar and getVariable methods?
public static int getVariable() {
return numberOfBicycles && id;
}
public static int getVariable() {
return id;
}
public static int getVariable() {
return id;
}
public static int getVariable() {
return numberOfBicycles;
}
Question 23 of 30 (worth 3 points)
The JButton class provides the functionality for an ordinary push button. A button can only contain text.
True
False
Check to review before finishing (will be flagged in Table of Contents)
Question 24 of 30 (worth 3 points)
Unlike radio buttons, in which many or none can be selected at once, check boxes only have one button selected at a time.
True
False
Check to review before finishing (will be flagged in Table of Contents)
Question 27 of 30 (worth 5 points)
Pick all that apply
Consider the following search method.
private static int search (int[] a, int target, int left, int right) {
if (left > right)
return 1?
else {
int midpoint = (left + right) / 2?
if (a[midpoint] == target)
return midpoint?
else if (a[midpoint] < target)
return search (a, target, midpoint + 1, right)?
else
return search (a, target, left, midpoint – 1)?
}
}
Which of the following might be described as the base case(s) for this method to end the recursion?
if (a[midpoint] < target)
if (a[midpoint] > target)
if (a[midpoint] == target)
if (left > right)
Check to review before finishing (will be flagged in Table of Contents)
Question 29 of 30 (worth 5 points)
Pick all that apply:
Consider the following class:
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
String cmd = evt.getActionCommand();
if (cmd.equals("Find"))
//Find player
String newName = Integer.toString(player.getValue(jtfName.getText()));
jtfHighScore.setText(newName);
jbtReplace.setVisible(true);
else (cmd.equals("Replace"))
{
//Find player
int newScore = Integer.parseInt(jtfHighScore.getText());
player.replaceVal(jtfName.getText(),
newScore);
String topScores= player.showAll();
jtxtTop.setText(topScores);
jtfName.setText("");
jtfHighScore.setText("");
}
else (cmd.equals("Add"))
{
//addressBook player = new addressBook();
int newScore = Integer.parseInt(jtfHighScore.getText());
player.add(jtfName.getText(), newScore);
jtfName.setText("");
jtfHighScore.setText("");
String topScores= player.showAll();
jtxtTop.setText(topScores);
}
}
Itentify two major problems with this code.
int newScore = Integer.parseInt(jtfHighScore.getText());
else (cmd.equals("Replace"))
else (cmd.equals("Add"))
String topScores
if (cmd.equals("Find"))
Check to review before finishing (will be flagged in Table of Contents)
A. int[] result={3, 1, 2, 6, 4, 2};printArray({3, 1, 2, 6, 4, 2});
B. int[]{3, 1, 2, 6, 4, 2};printArray(int[]);
C. int[] result;printArray(int[] result);
D.int[] result={3, 1, 2, 6, 4, 2};
printArray(result);
Explanation / Answer
Muyltiple Questions : Answering Qn 15.
int[] result={3, 1, 2, 6, 4, 2};
printArray(result);
A,B & C are having syntax errors.
Please post different questions separetely.
D.int[] result={3, 1, 2, 6, 4, 2};
printArray(result);