Use the following code to answer questions 24 and 25. public static void main(St
ID: 3720939 • Letter: U
Question
Use the following code to answer questions 24 and 25. public static void main(String[] args) { int i = 0; do { if (++i % 5 == 0) System.out.print(i + " "); } while (i < 20); }
24. How many times is the body of the loop repeated?
25. What is the exact output of the code?
26. For the following problem statement, would you include an if/else statement or a switch statement? Explain your answer. Be sure to address both types of statements in your answer. (You do not need to write the code.) Write a program that determines the bonus that should be paid to employees. Bonuses are derived as a percentage of the employee's salary, and the percentage is based on the department where the employee works. Employees in the sales department receive a bonus of 5%. Employees in the information technology department receive a bonus of 3%. All other employees receive a bonus of 2.5%.
27. Write a statement to declare a named constant called VERSION that has an String value of "1.1.57".
28. Can an enhanced for loop be used to initialize the all values of the array below to 100? Explain. int[] counter = new int[10];
29. Fill in the blank to specify that objects of a class named Purchase can be serialized. There may be more than one word in the blank. public class __________ {
30. What is the value assigned to answer? Show your work one operator at a time. int answer; answer = 6 * (3 + 5) % 7 + 5 / 2;
31. A salesperson earns a commission of 2% on sales up to $10,000, then earns a commission of 5% on any sales over $10,000. Write a sequence of statements to save the salesperson's commission to an integer value named commission, given his or her sales in an integer value named sales. (You may round all commission values down.)
Explanation / Answer
24. From 0 to 19, loop will be executed 20 times
25. Loop will print 5, 10, 15 and 20 since all are divisible by 5
26. Here bonus depends on department. And department is a constant value. So, it is better to use switch case. If else is used when the condition falls in range of values
27. enum VERSION{
"1.1.57"
}
28. No, enhanced for loop can't be used to initialize all the values in an array
29. public class Purchase implements Serializable
30. static final String VERSION = "1.157"
6*(3+5)%6+5/2
=>6*(8)%6+5/2
=>6*2+5/2
=>6*2+2.5
=>12+2.5=14.5
31.
int commission;
if(sales<=10000){
commission = sales*2/100;
}
else{
commission = 10000*2/100;
commission = commission + (sales-100000)*5/100;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.