Reference no: EM131565649
QUESTION 1
1. Complete the following method, which compares two parameters and returns -1, 0, or 1 if the first parameter is less than, equal to, or greater than the second parameter. Note answers are case sensitive.
public int compare(int a, int b) {
result; // declare variable of appropriate type. The variable will get its value then be returned.
if (a<b} {
= -1; // assignment -1 to which variable?
} else (a b) {// when the two parameters have same value, assign 0 to variable to be returned
= 0;
} else { // a must be great than b in this case
result = 1;
}
result; //one of the branching keywords.
}
QUESTION 2
1. The following switch statement decides the value of g based on the value of s (whose types have been declared elsewhere).
switch (s) {
case 9:
g="A";
;
case 8:
="B";
;
default:
g ="F";
}
Then complete the following code that is equivalent to the above switch statement.
if (s 9) {
g = "";
} else (s 8) {
g = "";
} {
g="F";
}
QUESTION 3
1. Indicate the values printed when the following code executes:
for (int i=1, j=5; i<=j; i++, j--) {
System.out.printf("%d %d %dn", i, j, i+j);
}
QUESTION 4
1. The following flowchart depicts a part of program that calculates 20 years of the annual value of an investment account with an initial balance of v, an annual additional investment a deposited into the account, and an annual rate of return r randomly drawn from a uniform distribution. Implement the program using for-loop.
Here is partially finished code. Fill in the blanks to complete it.
double v=1000, a=600; //initial value $1000; invest $600 at the end of each year
double r; // variable for storing annual rate of return
for (int = ; 20; i) {
r = -3 + 15*Math.random() ; //r is between -3 to 18%
v = v*(1+r/100)+a;
System.out.printf("%5 %5.2 %,10.0", i, r, v); // supply conversion characters
}
QUESTION 5
1. After the following code finishes executing, the value of the result variable is , the value of the i variable is . (Note: use numeric values for your answer)
int i=4, result=1;
while(i>1) {
result *= i;
i--;
}
Write code that uses the input string stream
: Write code that uses the input string stream inSS to read input data from string userInput, and updates variables userMonth, userDate, and userYear.
|
Define respect to security functions
: There are many critics of privatization, with respect to security functions. However, airport security screening has come under intense scrutiny in recent years
|
What cultural influences on financial reporting in america
: Lowly Coffee, Ltd. (a Vietnamese company) is a client of AJJ. What are the cultural influences on financial reporting in America
|
Discuss about the fleet safety program
: List and explain the significance of the three main areas of concentration in motor fleet security functions.
|
Implement the program using for-loop
: Implement the program using for-loop - Complete the method, which compares two parameters and returns
|
Explain at least two reasons how the death penalty
: Identify and explain at least two reasons how the death penalty DOES deter and supports/contributes to public safety
|
What are the indicators for using an anova
: What are the indicators for using an ANOVA? Create a research scenario in which it would be correct to use an ANOVA, including the research question.
|
Write a summary of the main parts of the paper
: Introduction: Objectives of the thesis, referring to the guidelines Presentation of the approved topic. Summary of the main parts of the paper.
|
Compute the cost of goods sold
: Compute the cost of goods sold, cost of ending merchandise inventory, and gross profit using the FIFO inventory costing method
|