2.02 Boolean Expressions
Write yes or no questions in Java with the relational operators ==, !=, <, >, <=, and >=.
- 1. LxD Cycle Process
- 2. Lesson Plan
- 3. Reference Guide
- 4. Code Examples
- A. Simple: Booleans in Code
- Code Runner Challenge
- 5. Hacks & Practice Tasks
- 6. Grading Plan (1 Point Total)
- 7. Lesson Revisions & Feedback Evidence
- 8. Summary
- 9. References
1. LxD Cycle Process
Empathize: Students read = and == as the same symbol and are surprised when the compiler rejects one or the program silently does the wrong thing. They also treat comparison results as something that only lives inside an if.
Define:
- POV: CSA students need to see a comparison as a value, not only as a condition, because the AP exam asks them to store, print and combine Boolean results.
- Learning Goal: Students will evaluate relational expressions by hand, store results in
booleanvariables, and find the difference between assignment and comparison.
Ideate:
- HMW Question: How might we make the result of a comparison visible as a value, so students stop thinking it only exists inside an
if? - Activity: A live comparison lab where changing operands updates the printed
trueorfalse, followed by a true-or-false drill and a bug hunt.
Prototype & Test: The comparison lab runs before any if statement appears, so students meet boolean as a data type first and as a condition second.
2. Lesson Plan
Learning Objective: Evaluate Boolean expressions that use relational operators in program code.
Success Criteria: You can predict whether a relational expression is true or false, store the result in a boolean variable, and explain why = and == are not interchangeable.
Tech Talk & Introduction (5 minutes)
A Boolean expression is a question with only two possible answers. Java answers it with true or false, and that value can be stored just like a number.
- The relational operators are
==,!=,<,>,<=and>=. =assigns a value.==asks whether two values are equal. Mixing them up is the most common bug in this topic.- The result of a comparison is a
boolean, soboolean passed = score >= 60;is legal and often clearer than repeating the comparison.
3. Reference Guide
Key Ideas
- A Boolean expression evaluates to exactly one of two values:
trueorfalse. - Relational operators compare two values:
==!=<><=>=. ==asks “are these equal?” while=assigns a value. Mixing them up is the most common bug in this unit.- Arithmetic runs first, then the comparison:
x + 1 > 5adds before it compares. - Relational operators work on numbers (
int,double) andchar. Use.equalsfor Strings (more in 2.6). - A Boolean value can be stored in a
booleanvariable:boolean isAdult = age >= 18;
The Six Relational Operators
| Operator | Question it asks | Example (x = 7) | Value |
|---|---|---|---|
== |
equal to? | x == 7 |
true |
!= |
not equal to? | x != 7 |
false |
< |
less than? | x < 10 |
true |
> |
greater than? | x > 10 |
false |
<= |
less than or equal? | x <= 7 |
true |
>= |
greater than or equal? | x >= 8 |
false |
- Integer division still applies:
10 / 4 == 2istruebecause10 / 4is2. %gives the remainder:x % 2 == 0is the standard test for “is x even?”.
4. Code Examples
A. Simple: Booleans in Code
Run this program. Then change temperature to 100, 72, and -5 and predict each line before you press Run.
Code Runner Challenge
Boolean demo: store comparisons in boolean variables and print them.
View IPYNB Source
// CODE_RUNNER: Boolean demo: store comparisons in boolean variables and print them.
public class BooleanDemo {
public static void main(String[] args) {
int temperature = 85;
int limit = 90;
boolean isHot = temperature > limit;
boolean isFreezing = temperature <= 32;
boolean isEven = temperature % 2 == 0;
System.out.println("temperature > limit: " + isHot);
System.out.println("temperature <= 32: " + isFreezing);
System.out.println("temperature % 2 == 0: " + isEven);
System.out.println("temperature != limit: " + (temperature != limit));
System.out.println("temperature + 5 >= limit: " + (temperature + 5 >= limit));
}
}
BooleanDemo.main(null);
5. Hacks & Practice Tasks
Prepare your submission IPYNB
- Create a new notebook in your portfolio homework area:
_notebooks/homework. - Add one markdown cell at the top with the frontmatter:
---
layout: post
title: CSA Unit 2.02 Boolean Expressions HW
categories: [Java, Boolean-Expressions]
lesson_language: Java
lesson_topic: Boolean-Expressions HW
lesson_source: APCSA
lesson_type: lesson
permalink: /csa/unit_02/2_2_hw
author: yourGithubID
---
- Add code cells for the Popcorn Hack and the Homework Hack. Ensure all code runs and output is visible.
- Include a markdown cell before each code section explaining the concept.
Submission Safety Rules (Read First)
[IMPORTANT] To avoid grading errors, follow these rules exactly:
- Write your prediction before you run each code section
- Execute every code cell and leave the output visible
- Show your work for any hand-traced prediction
- Do not just copy code; explain what each line does
- Label each question clearly
Activity 1: Live Comparison Lab
Move the sliders. Every println line re-evaluates instantly. Try to make every line print true, then every line print false.
Activity 2: True or False?
Given the three variables below, sort every expression into the TRUE or FALSE bucket. Watch out for integer division.
Click an item, then click a bucket. Or drag it. Click an item inside a bucket to send it back.
Activity 3: Spot the Bug
Which line will NOT compile?
What is the value of 7 / 2 == 3.5?
Which expression is true exactly when n is a multiple of 5?
Popcorn Hack (In-Class)
This program has two bugs. One stops it from compiling, the other prints the wrong answer. Fix both so it prints Bonus unlocked: true and Exact score: false.
Code Runner Challenge
Popcorn hack: fix the two bugs so both lines print the expected values.
View IPYNB Source
// CODE_RUNNER: Popcorn hack: fix the two bugs so both lines print the expected values.
public class BonusCheck {
public static void main(String[] args) {
int score = 120;
int target = 100;
// Bug 1: this line does not compile
boolean bonus = score => target;
// Bug 2: this should ask whether score is EXACTLY equal to target
boolean exact = score != target;
System.out.println("Bonus unlocked: " + bonus);
System.out.println("Exact score: " + exact);
}
}
BonusCheck.main(null);
Homework Hack
Short and specific.
- Complete the runner below: write the four Boolean expressions described in the comments and print them.
- Answer the two quick checks under it.
Code Runner Challenge
Homework: replace each false with a Boolean expression so the expected values print.
View IPYNB Source
// CODE_RUNNER: Homework: replace each false with a Boolean expression so the expected values print.
public class SpeedCheck {
public static void main(String[] args) {
int speed = 68;
int limit = 65;
int age = 17;
// 1. true when the driver is over the limit
boolean speeding = false; // TODO
// 2. true when the driver is going exactly the limit
boolean exactLimit = false; // TODO
// 3. true when the driver is at least 18
boolean adult = false; // TODO
// 4. true when speed is an odd number (use %)
boolean oddSpeed = false; // TODO
System.out.println("speeding: " + speeding); // expected: true
System.out.println("exactLimit: " + exactLimit); // expected: false
System.out.println("adult: " + adult); // expected: false
System.out.println("oddSpeed: " + oddSpeed); // expected: false
}
}
SpeedCheck.main(null);
What does this print?
What does this print?
6. Grading Plan (1 Point Total)
Classroom Rubric
-
0.2 points: Popcorn completion Student fixed both bugs so the program compiles and prints
Bonus unlocked: trueandExact score: false. -
0.8 points: Homework completion
- 0.5 Four expressions: The four Boolean expressions described in the runner comments are written correctly and printed.
- 0.2 Quick checks: Both quick check questions answered with the reasoning shown.
- 0.1 Notebook quality: Every code cell executed with output visible, and a markdown cell before each code section explaining the concept.
Quick Validation Checklist
- Present: all four expressions print a
trueorfalsevalue - Present: both Popcorn bugs fixed, with a comment naming each one
- Absent:
=used where==was intended - Test: output reads
Bonus unlocked: trueandExact score: false
7. Lesson Revisions & Feedback Evidence
Feedback Received: Team review of the Unit 2 set found that these lessons did not follow the section format used by the Unit 1 lessons, and that they ended without the assignment submission form every other CSA lesson provides.
Revision Made: The lesson was reorganised into the shared CSA lesson format, so it now opens with the LxD cycle and lesson plan, states its reference material before the code, and groups the activities, Popcorn Hack and Homework Hack under one practice section. The duplicate lesson heading was removed, and the page now renders the standard Submit Assignment form at the end.
Design Decision Kept: The comparison lab runs before any if statement appears, so students meet boolean as a data type first and as a condition second.
Open Item: Record peer feedback from the team teach delivery here once the lesson has been taught.
8. Summary
- Boolean expressions are
trueorfalse; relational operators build them. ==compares,=assigns.- Arithmetic (including integer division and
%) happens before the comparison. x % k == 0tests divisibility;x % 2 == 0tests even.- Next lesson: using Boolean expressions to make decisions with
if.
9. References
College Board Course and Exam Description
Topic 2.2, Boolean Expressions, is required content on the AP Computer Science A Exam. The objective quoted in section 2 of this lesson is the College Board’s own wording for this topic, and the activities, Popcorn Hack and Homework Hack are all written against it.
Outside Academic Reference
The relational operators and the boolean type behave exactly as the language specification defines them: a numeric comparison produces a value of type boolean, which is why it can be assigned to a variable.
Reference List
College Board. (2025). AP Computer Science A: Course and exam description. https://apcentral.collegeboard.org/courses/ap-computer-science-a
Gosling, J., Joy, B., Steele, G., Bracha, G., Buckley, A., Smith, D., & Bierman, G. (2023). The Java language specification: Java SE 21 edition. Oracle America. https://docs.oracle.com/javase/specs/jls/se21/html/
Submit Assignment
Need to update a submission later? Open the submissions dashboard.