Unit3 Boolean If
Unit3 Boolean If
unit 3 Name
A A
B B
C C
D D
E Nothing is printed.
AP Computer Science A Test Booklet
unit 3
2. A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all three
bonus questions correctly and no extra points otherwise. Assume that the boolean
variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the
particular question correctly.
Each variable was assigned true if the answer was correct and false if the answer was incorrect.
Which of the following code segments will properly update the variable grade based on a student's
performance on the bonus questions?
I. if (bonusOne && bonusTwo && bonusThree)
grade += 5;
II. if (bonusOne || bonusTwo || bonusThree)
grade += 5;
III. if (bonusOne)
grade += 5;
if (bonusTwo)
grade += 5;
if (bonusThree)
grade += 5;
A I only
B II only
C III only
D I and III
E II and III
3. Assume that the boolean variables a, b, c, and d have been declared and initialized. Consider the following
expression.
!( !( a && b ) || ( c || !d ))
Which of the following is equivalent to the expression?
AP Computer Science A Test Booklet
unit 3
B ( a || b ) && ( !c && d )
C ( a && b ) || ( c || !d )
D ( !a || !b ) && ( !c && d )
E !( a && b ) && ( c || !d )
A valueOne.equals((Object) valueTwo)
B valueOne == valueTwo
C valueOne.compareTo((Object) valueTwo) == 0
D valueOne.compareTo(valueTwo) == 0
E valueOne.equals(valueTwo)
5. Which of the following best describes the value of the Boolean expression shown below?
a && !(b || a)
AP Computer Science A Test Booklet
unit 3
C The value is true when a has the value false, and is false otherwise.
D The value is true when b has the value false, and is false otherwise.
E The value is true when either a or b has the value true, and is false otherwise.
unit 3
false
A false
false
false
B false
true
true
C false
false
true
D false
true
true
E true
true
AP Computer Science A Test Booklet
unit 3
The following table shows several examples of input values and the results that should be produced by calling
someProcess.
Which of the following code segments could be used to replace /* body of someProcess */ so that
the method will produce the results shown in the table?
I. if ((n % 3 == 0) && (n % 4 == 0))
return n * 10;
else
return n;
return n;
III. if (n % 3 == 0)
if (n % 4 == 0)
return n * 10;
return n;
AP Computer Science A Test Booklet
unit 3
A I only
B II only
C III only
D I and III
E II and III
AP Computer Science A Test Booklet
unit 3
A II only
B III only
C I and II only
A true
B false
C a == b
D a != b
unit 3
10. Vehicles are classified based on their total interior volume. The classify method is intended to return a
vehicle classification String value based on total interior volume, in cubic feet, as shown in the table below.
Vehicle size class Total interior volume
unit 3
A 80
B 90
C 105
D 109
E 115