Docsity

JAVA EXAM 2 EXAM SCRIPT 2026 FULL SOLUTION TEST BANK, Exams of Object Oriented Programming

Toggle sidebar
bg1
JAVA EXAM 2 ACTUAL EXAM PAPER 2026
QUESTIONS SOLUTIONS GRADED A+
โ—โ— Java Expression not equal to. Answer: !=
โ—โ— Java expression greater than. Answer: >
โ—โ— Java expression greater than or equal to. Answer: >=
โ—โ— Java expression less than. Answer: <
โ—โ— Java expression less than or equal to. Answer: <=
โ—โ— What is the data type of a comparison expression. Answer: boolean
โ—โ— For comparison operators that have two symbols, is there a space
present?. Answer: no
โ—โ— For comparison operators does the equals sign come first or second..
Answer: Always second
โ—โ— The condition of a Java if statement must be,. Answer: Boolean
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download JAVA EXAM 2 EXAM SCRIPT 2026 FULL SOLUTION TEST BANK and more Exams Object Oriented Programming in PDF only on Docsity!

JAVA EXAM 2 ACTUAL EXAM PAPER 2026

QUESTIONS SOLUTIONS GRADED A+

โ—โ— Java Expression not equal to. Answer: != โ—โ— Java expression greater than. Answer: > โ—โ— Java expression greater than or equal to. Answer: >= โ—โ— Java expression less than. Answer: < โ—โ— Java expression less than or equal to. Answer: <= โ—โ— What is the data type of a comparison expression. Answer: boolean โ—โ— For comparison operators that have two symbols, is there a space present?. Answer: no โ—โ— For comparison operators does the equals sign come first or second.. Answer: Always second โ—โ— The condition of a Java if statement must be,. Answer: Boolean

contained in parentheses โ—โ— compound statement. Answer: a list of statements enclosed in a pair of braces โ—โ— Each branch of a Java if statement consists of at most. Answer: one statement, although the statement may be compound. โ—โ— Suppose n1 and n2 are two int variables that have been given values. Write a Boolean expression that returns true if the value of n1 is greater than or equal to the value of n2; otherwise, it should return false.. Answer: n1 >= n โ—โ— Suppose n1 and n2 are two int variables that have been given values. Write an if-else statement that outputs "n1" if n1 is greater than or equal to n2, and that outputs "n2" otherwise.. Answer: if (n1 >= n2) System.out.println("n1"); else System.out.println("n2"); โ—โ— Are braces optional for if single controlled statements. Answer: yes

โ—โ— Dr Java is an IDE which stands for. Answer: Integrated Development Environment โ—โ— What do IDE's bundle together. Answer: code editor, compiler, and debugger โ—โ— code editor. Answer: colorizes and indents code โ—โ— compiler. Answer: clickable error messages that move the edit cursor to the location of the error โ—โ— State the recommended five steps to follow when writing a program. Answer: analysis program design test design coding test execution and debugging โ—โ— State questions that should be asked and answered during analysis.. Answer: What is the overall goal? What are the inputs and outputs? What are the detailed requirements? What hints/helps are provided?

โ—โ— pseudocode. Answer: statements that describe what you want the code to do without worrying about ()'s, {}'s, ;'s, order of vars in assignment, ==, etc. โ—โ— why is it simpler to write pseudocode than java code. Answer: because there is No need to worry about ()'s, {}'s, ;'s, order of vars in assignment, ==, etc. only what you want the program to accomplish. โ—โ— why it is recommended to perform program design prior to coding?. Answer: to avoid mistakes, make sure you understand the program, and save time โ—โ— why it is recommended to design program tests before writing Java code?. Answer: to help understand the problem and helpthink of different situations that can occur and troubleshoot problems in the code that might occur before testing the code. โ—โ— how does the Java switch statement is similar to and different from a if-else statement. Answer: similar: only other kind of java statement that implements multiway branching

โ—โ— What is the output produced by the following code? int key = 1; switch (key + 1) { case 1: System.out.println("Apples"); break; case 2: System.out.println("Oranges"); break; case 3: System.out.println("Peaches"); case 4: System.out.println("Plums"); break; default: System.out.println("Fruitless"); }. Answer: oranges

โ—โ— What would be the output in Self-Test Exercise 10 if the first line were changed to the following? int key = 3;. Answer: plumes โ—โ— What would be the output in Self-Test Exercise 10 if the first line were changed to the following? int key = 5;. Answer: fruitless โ—โ— Suppose variable1 and variable2 are two variables that have been given values. How do you test whether they are equal when the variables are of type int? How do you test whether they are equal when the variables are of type String?. Answer: When the variables are of type int, you test for equality using ==, as follows: variable1 == variable When the variables are of type String, you test for equality using the method equals, as follows: variable1.equals(variable2)

programsDone are both of type int.. Answer: if ( (exam >= 60) && (programsDone >= 10) ) System.out.println("Passed"); else System.out.println("Failed"); โ—โ— Write an if-else statement that outputs the word "Emergency" provided the value of the variable pressure is greater than 100 or the value of the variable temperature is greater than or equal to 212. Otherwise, the if-else statement should output the word "OK". The variables pressure and temperature are both of type int.. Answer: if ( (pressure > 100) || (temperature >= 212) ) System.out.println("Emergency"); else System.out.println("OK"); โ—โ— Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10. (Give your answer as one of the values true or false.) a. (count == 0) && (limit < 20)

b. count == 0 && limit < 20 c. (limit > 20) || (count < 5) d. !(count == 12) e. (count == 1) && (x < y) f. (count < 10) || (x < y) g. !( ((count < 10) || (x < y)) && (count >= 0) ) h. ((limit/count) > 7) || (limit < 20) i. (limit < 20) || ((limit/count) > 7) j. ((limit/count) > 7) && (limit < 0) k. (limit < 0) && ((limit/count) > 7). Answer: a. true. b. true. Note that expressions a and b mean exactly the same thing. Because the operators == and < have higher precedence than &&, you do not need to include the parentheses. The parentheses do, however, make it easier to read. Most people find the expression in option a easier to read than the expression in option b, even though they mean the same thing. c. true. d. true. e. false. Because the value of the first subexpression, (count == 1), is false,

you know that the entire expression is true without bothering to evaluate the second subexpression. Thus, the second subexpression, ((limit/count) > 7), is never evaluated, so the fact that it involves a division by zero is never notic โ—โ— Does the following sequence produce a division by zero? int j = - 1; if ((j > 0) && (1/(j+1) > 10)) System.out.println(i);. Answer: No. Since (j > 0) is false and Java uses short-circuit evaluation for &&, the expression (1/(j+1) > 10) is never evaluated. โ—โ— Convert the following expression to an equivalent fully parenthesized expression: bonus + day * rate / correctionFactor * newGuy - penalty. Answer: ((bonus + (((day * rate) / correctionFactor) * newGuy)) - penalty) โ—โ— while statement. Answer: used to repeat a portion of code (i.e., the loop body) based on the evaluation of a Boolean expression โ—โ— for statement. Answer: most commonly used to step through an integer variable in equal increments

โ—โ— do-while statement. Answer: used to execute a portion of code (i.e., the loop body), and then repeat it based on the evaluation of a Boolean expression โ—โ— for statement(____,______,______). Answer: initializing, boolean_Expression, update โ—โ— differencce between while and do-while. Answer: do-qhile is useful when we want to execute the loop body at least once โ—โ— can java while and for loops do the same thing. Answer: yes โ—โ— infinite loops. Answer: the boolean expression remains true, making the loop run forever โ—โ— Which Java expressions are especially prone to loops. Answer: == and != โ—โ— sentinel value. Answer: an illegal value that is used to end a list of values โ—โ— nested loops. Answer: inner loop iterates from beginning to end for each single iteration of the outer loop

โ—โ— Explain how to overcome limitations of the provided robot methods-

  • for example, there is no direct way to find a window--by combining the information provided by various methods.. Answer: you can use rightIsWall(), and turn right if it is not then ask frontIsClear() โ—โ—