Boolean Expressions
Help Questions
AP Computer Science A › Boolean Expressions
An access system grants entry when hasKeyCard || isAdmin; what will happen if this condition evaluates to false?
Access is granted only if isAdmin is false
Access is granted only if hasKeyCard is false
Access is granted because one check is assumed
Access is denied because neither condition is true
Explanation
This question tests AP Computer Science A skills in boolean expressions and their use in controlling program flow and iteration. Boolean expressions evaluate to true or false and are crucial in decision-making and loops. They use operators like && (and), || (or), and ! (not) to form conditions that guide program logic. Choice B is correct because when the expression hasKeyCard || isAdmin evaluates to false, it means NEITHER condition is true - the person doesn't have a key card AND is not an admin, so access is denied. Choice A is incorrect because it misunderstands what happens when an OR expression is false - for || to be false, both operands must be false. To help students: Remember that || (OR) is only false when both conditions are false. Create a truth table showing that false || false = false, while any other combination with || results in true.
In a game, if (hasPowerUp && !isEnemyNear) allows a speed boost; which condition must be true to execute the boost block?
hasPowerUp is false and isEnemyNear is false
hasPowerUp is true and isEnemyNear is false
hasPowerUp is true, regardless of isEnemyNear
hasPowerUp is true and isEnemyNear is true
Explanation
This question tests AP Computer Science A skills in boolean expressions and their use in controlling program flow and iteration. Boolean expressions evaluate to true or false and are crucial in decision-making and loops. They use operators like && (and), || (or), and ! (not) to form conditions that guide program logic. Choice A is correct because the expression hasPowerUp && !isEnemyNear requires the player to have a power-up AND there must NOT be an enemy nearby - the ! operator negates isEnemyNear, so it must be false. Choice B is incorrect because it misinterprets the negation operator - if isEnemyNear is true, then !isEnemyNear is false, making the entire expression false. To help students: Practice reading negations carefully - !true equals false and !false equals true. Use real-world analogies: "You can only use the speed boost if you have it AND the coast is clear."
A library allows borrowing when isAvailable && !isReserved; what will happen if isReserved becomes true?
Borrowing depends only on isAvailable
Borrowing is allowed only for members
Borrowing is denied even if the book is available
Borrowing is allowed because isAvailable is checked
Explanation
This question tests AP Computer Science A skills in boolean expressions and their use in controlling program flow and iteration. Boolean expressions evaluate to true or false and are crucial in decision-making and loops. They use operators like && (and), || (or), and ! (not) to form conditions that guide program logic. Choice B is correct because when isReserved becomes true, the expression isAvailable && !isReserved will evaluate to false (since !true is false), denying borrowing even if the book is available. Choice A is incorrect because it ignores the impact of isReserved being true - the && operator requires both conditions to be true, and !isReserved becomes false when isReserved is true. To help students: Trace through the expression step by step - if isReserved is true, then !isReserved is false, and true && false equals false. Emphasize that && requires ALL conditions to be true for the overall result to be true.
An access system runs while (!hasKeyCard && !isAdmin) to keep showing “Denied”; how does this affect loop iteration?
It repeats while either is true
It repeats only when hasKeyCard is true
It repeats until both become true
It repeats while both are false
Explanation
This question tests AP Computer Science A skills in boolean expressions and their use in controlling program flow and iteration. Boolean expressions evaluate to true or false and are crucial in decision-making and loops. They use operators like && (and), || (or), and ! (not) to form conditions that guide program logic. Choice B is correct because the expression !hasKeyCard && !isAdmin means the loop continues while the user does NOT have a key card AND is NOT an admin - essentially while both original conditions are false. Choice C is incorrect because it misinterprets the logic; the && operator with negations means both must be false, not that either being true continues the loop. To help students: Use De Morgan's Laws to understand negated compound expressions - !(A || B) equals !A && !B. Practice converting between different forms of boolean expressions and trace through examples with truth tables.
A traffic-light controller uses if (isEmergency || timeOfDay.equals("NIGHT")); which condition needs to be true to switch to flashing mode?
Only isEmergency must be true
Neither isEmergency nor timeOfDay is NIGHT
Both isEmergency is true and timeOfDay is NIGHT
Either isEmergency is true or timeOfDay is NIGHT
Explanation
This question tests AP Computer Science A skills in boolean expressions and their use in controlling program flow and iteration. Boolean expressions evaluate to true or false and are crucial in decision-making and loops. They use operators like && (and), || (or), and ! (not) to form conditions that guide program logic. Choice B is correct because the || (OR) operator means the condition is true if either isEmergency is true OR timeOfDay equals "NIGHT" - only one condition needs to be met to switch to flashing mode. Choice C is incorrect because it describes an AND relationship, which would require both conditions to be true simultaneously, not what the || operator provides. To help students: Create scenarios and test them against the boolean expression - if it's an emergency during the day, does it flash? Yes. If it's night but no emergency? Also yes. Emphasize that || means "at least one" while && means "all must be true."