Answer the questions please 1 private List values return tr
Answer the questions please:
1-
private List values;
/** @return true if for every k in the range 0 < k < values.size(),
* values.get(k) is less than values.get(k-1).
* false otherwise
*/
public boolean isDecreasing() {
boolean isDecr;
/* statement 1 */
for (int k = 1; k < values.size(); k++) {
int prev = values.get(k-1).intValue();
int curr = values.get(k).intValue();
/* statement 2 */
} // end for
return isDecr;
} // end method isDecreasing
Consider the following replacements for statements 1 and 2
/* statement 1 */ /* statement 2 */
I. isDecr = true; if (curr >= prev) isDecr = false;
II. isDecr = false; if (curr < prev) isDecr = true;
III. isDecr = true; isDecr = isDecr && (curr < prev);
Which of the proposed replacements can be used so that isDecreasing() will work as intented?
Question 1 options:
I only
II only
III only
I and III
II and III
2- Consider the following code segment:
if (x % 2 == 0)
x = x - 1;
if (x % 2 != 0)
x = x + 1;
If x is greater than 0 before the code segment is executed, which of the following states is (are) true regarding the final value of x after the code segment has executed?
I. The final value of x is always even.
II. The final value of x is equal to its initial value when x is initially even.
III. The final value of x is equal to its initial value when x is initially odd.
Question 2 options:
I only
II only
III only
I and II
II and III
3- Consider the following segments of java code. Assume that there are no intentional syntax errors.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Observer extends Application implements EventHandler<ActionEvent>{
@Override
public void start(Stage primaryStage) {
Button button = new Button(\"Click Me\");
/** MISSING STATEMENT **/
StackPane root = new StackPane();
root.getChildren().add(button);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle(\"Button\");
primaryStage.setScene(scene);
primaryStage.show();
}// end start method
@Override
public void handle(ActionEvent t) {
System.out.println(\"Click\");
}// end method handle
public static void main(String[] args) {
launch(args);
} // end main method
}// end Observer class
What should replace /** MISSING STATEMENT **/ in order for the button to work with the provided handle method?
Question 3 options:
this.setOnAction(this);
button.setOnAction(button);
this.setOnAction(button);
button.setOnAction(this);
this.setOnAction(event);
4- Consider a 32-bit data type such as java\'s integer data type. How many unique/distinct possible values could a variable of that type potentially be assigned? Choose the closest approximate answer.
Question 4 options:
approximately one hundred or less
approximately one thousand
approximately one million
approximately one billion
approximately one trillion or higher
5- Consider the following segment of java-like code. Assume that there are no intentional syntax errors.
public abstract class Dog {
public abstract void speak();
} // end class Dog
public class LoudDog extends Dog {
public void speak() {
System.out.print(\"WOOF \");
} // end method speak
} // end class LoudDog
public class BabyLoudDog extends LoudDog {
public void speak () {
System.out.print(\"yip \");
} // end method speak
} // end class BabyLoudDog
Consider the following code segment.
LoudDog fido = new LoudDog();
BabyLoudDog rover = new BabyLoudDog();
fido.speak();
rover.speak();
What is printed as a result of executing the code segment?
Question 5 options:
WOOF WOOF
WOOF yip
WOOF WOOF yip
WOOF yip WOOF
Nothing is printed because speak() is an abstract method
6- Consider the following segment of code in a java-like programming language. Assume that there are no syntax errors.
public class Example {
private int x;
public void method (int y) {
y = y * 2;
x = y;
} // end method method
public int getValue() {
return x;
} // end method getValue
} // end class Example
The following code segment appears in a method in another class.
Example obj = new Example ();
int y = 10;
obj.method(y);
obj.method(y);
System.out.println(y + \" \" + obj.getValue());
What is printed as a result of executing the code segement?
Question 6 options:
10 20
10 40
20 20
20 40
40 40
7- Consider the following segment of code in a java-like programming language. Assume that there are no syntax errors.
boolean A = true;
boolean B = false;
boolean C = true;
boolean D = A || C;
boolean E = A && B || C;
boolean F = A || B && C;
At the end of this segment of code, what is the value of the variable E?
Question 7 options:
False
True
It depends
Undefined
I do not know
8- Consider the following segment of code in a java-like programming language. Assume that there are no syntax errors.
int[] m = {2,3,4,5,6};
int n = 0;
int x = 0;
for (int val = 0; val < m.length; val++) {
if (m[val] % 2 == 1) {
n = n + m[val];
x = x + 1;
} // end-if
} // end-for
Which of the following is the most likely intent for the code segment above?
Question 8 options:
Calculating the total sum of the values held in array m.
Calculating the average of the values held in array m.
Calculating the number of even values in array m.
Calculating the average of the odd values in array m.
Calculating the number of values in array m.
| I only | |
| II only | |
| III only | |
| I and III | |
| II and III |
Solution
1. I only
Explanation:
***************
I. isDecr = true; if (curr >= prev) isDecr = false;
At first statement , isDecr is intialized to isDecr = true
And in each iteration we need to check curr is greater than equal prev
Atleast if one of the k value is not qualifies the given condition
,then isDecr will become false. Hope you understand.
Ex: 1 3 2 4 5
Here 3 >=2 condition fails return false.
=========================================================================
2. II only
Explanation:
***************
II. The final value of x is equal to its initial value when x is initially even.
Since , If we take x value as 4
if(x%2==0) is true since 4%2==0
and hence x = x- 1 i.e x= 4-1 =3
if(x%2==0) is true since 3%2!=0
and hence x = x +1 i.e x = 3+1 =4
At final x = 4 which is the initial value. Hence proved
=========================================================================
3. button.setOnAction(this);
Explanation:
***************
As per the java docs setOnAction function prototype is
public final void setOnAction(EventHandler<ActionEvent> value)
and hence button.setOnAction(this) is the correct statement.
Since this is current class object which is type of event.
=========================================================================
4. approximately one billion
Explanation:
***************
As per java docs int value range is