1. LxD Cycle Process

Empathize: Students assume something must happen when a condition is false, so a one-way if that simply skips its block reads as broken. They also drop braces and are then surprised which lines ran.

Define:

  • POV: CSA students need to see exactly which lines execute for a given condition, because the AP exam tests tracing far more than it tests writing new if statements.
  • Learning Goal: Students will trace one-way and two-way selection, predict output before running, and assemble a correct if-else from shuffled lines.

Ideate:

  • HMW Question: How might we make the path a program takes visible, so students can see the skipped lines rather than assume them?
  • Activity: A path tracer that highlights the executing line, a trace of an if with no else, an output prediction, and a build-the-program ordering task.

Prototype & Test: Activity 2 deliberately uses an if with no else so the false path is visible as nothing happening, which is the case students most often get wrong.


2. Lesson Plan

Learning Objective: Represent branching logical processes by using selection statements.

Success Criteria: You can predict which branch of an if or if-else runs, trace a one-way if where the condition is false, and place braces so the intended statements are inside the branch.

Tech Talk & Introduction (5 minutes)

An if statement runs a block only when its condition is true. Adding else gives a second block that runs when the condition is false.

  • A one-way if with a false condition runs nothing and moves on. That is normal, not an error.
  • if-else always runs exactly one of the two blocks.
  • Without braces, only the next single statement belongs to the branch. This is a frequent source of silent bugs.

3. Reference Guide

Key Ideas

  • An if statement runs its body only when the condition is true. This is one way selection.
  • if … else chooses between two blocks. Exactly one of them runs. This is two way selection.
  • The condition must be a Boolean expression: if (x > 5), never if (x).
  • Braces { } group the statements that belong to the if. Without braces, only the very next statement belongs to it.
  • Code after the if or if-else runs no matter which path was taken.

Shape of the Statement

if (condition) {
    // runs only when condition is true
} else {
    // runs only when condition is false
}
// always runs
  • The else part is optional.
  • No semicolon after if (condition). Writing if (x > 5); makes an empty body, a silent bug.

4. Code Examples

A. Simple: if-else in Code

Run the program, then change number to an odd value and run again.

Code Runner Challenge

if-else demo: even or odd. Change number and run again.

View IPYNB Source
// CODE_RUNNER: if-else demo: even or odd. Change number and run again.
public class EvenOdd {
    public static void main(String[] args) {
        int number = 2;   // change this to an odd number and run again

        if (number % 2 == 0) {
            System.out.println(number + " is even");
        } else {
            System.out.println(number + " is odd");
        }
        System.out.println("This line always prints.");
    }
}
EvenOdd.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

5. Hacks & Practice Tasks

Prepare your submission IPYNB

  1. Create a new notebook in your portfolio homework area: _notebooks/homework.
  2. Add one markdown cell at the top with the frontmatter:
---
layout: post
title: CSA Unit 2.03 if Statements HW
categories: [Java, If-Statements]
lesson_language: Java
lesson_topic: If-Statements HW
lesson_source: APCSA
lesson_type: lesson
permalink: /csa/unit_02/2_3_hw
author: yourGithubID
---
  1. Add code cells for the Popcorn Hack and the Homework Hack. Ensure all code runs and output is visible.
  2. 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: Which Path Runs?

Slide the age. The highlighted lines are the ones Java executes. Notice the last line always runs.

Driver's License Checker
Green lines run. Faded lines are skipped.

Activity 2: Trace an if Without an else

Step through the program. Change temp to see the body get skipped entirely.

Jacket Check
One way selection: the body runs zero times or one time.

Activity 3: Predict the Output

Predict the Output
Braces and semicolons change everything. Read carefully.
Question 1

What does this code print?

int x = 3;
if (x > 5)
System.out.println("A");
System.out.println("B");
Question 2

What does this code print?

int score = 40;
if (score >= 60) {
System.out.println("Pass");
} else {
System.out.println("Retake");
}
System.out.println("Done");
Question 3

What is wrong with this code?

int coins = 3;
if (coins > 5);
{
System.out.println("Rich!");
}

Activity 4: Build the Program

Arrange the lines so the program prints Even when n is even and Odd otherwise, then prints Checked!.

Assemble an if-else
Every brace matters. Use the arrows or drag the lines.
int n = 12;
if (n % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
System.out.println("Checked!");

Popcorn Hack (In-Class)

Find and fix the two errors so the program compiles and prints Number is even.

Code Runner Challenge

Popcorn hack: two errors. Hint: Strings use double quotes, and every statement ends with a semicolon.

View IPYNB Source
// CODE_RUNNER: Popcorn hack: two errors. Hint: Strings use double quotes, and every statement ends with a semicolon.
public class FixMe {
    public static void main(String[] args) {
        int number = 2;

        if (number % 2 == 0) {
            System.out.println('Number is even');
        } else {
            System.out.println("Number is odd")
        }
    }
}
FixMe.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack

Two short tasks.

  1. Finish the runner below. A store gives free shipping on orders of $50 or more. Print Free shipping or Shipping: $5.99, then always print the order total.
  2. Answer the quick check.

Code Runner Challenge

Homework: write an if-else for free shipping, then a line that always runs.

View IPYNB Source
// CODE_RUNNER: Homework: write an if-else for free shipping, then a line that always runs.
public class Shipping {
    public static void main(String[] args) {
        double orderTotal = 42.50;   // test with 42.50 and with 75.00

        // TODO: if orderTotal is at least 50, print "Free shipping"
        // TODO: otherwise print "Shipping: $5.99"

        // TODO: always print "Order total: $" followed by orderTotal
    }
}
Shipping.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
Homework Quick Check
One question.

How many lines does this code print? Type a number.

int level = 7;
if (level > 10) {
System.out.println("Expert");
System.out.println("Unlocked");
}
System.out.println("Level " + level);

6. Grading Plan (1 Point Total)

Classroom Rubric

  • 0.2 points: Popcorn completion Student found and fixed both errors so the program compiles and prints Number is even.

  • 0.8 points: Homework completion

    • 0.5 Free shipping branch: Free shipping or Shipping: $5.99 prints correctly for orders above and below the $50 threshold.
    • 0.2 Always-run line: The order total prints in both cases, showing the statement was placed outside the branch.
    • 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: both branches tested with a value above and below 50
  • Present: braces around every branch body
  • Present: quick check answered
  • Test: an order of exactly 50 takes the free shipping branch

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: Activity 2 deliberately uses an if with no else so the false path is visible as nothing happening, which is the case students most often get wrong.

Open Item: Record peer feedback from the team teach delivery here once the lesson has been taught.


8. Summary

  • if (condition) { ... } runs the body when the condition is true, otherwise skips it.
  • if ... else runs exactly one of two blocks.
  • Use braces every time; without them only the next statement belongs to the if.
  • Never put a semicolon right after if (condition).
  • Statements after the if run no matter what.
  • Next lesson: putting an if inside another if, and else if chains.

9. References

College Board Course and Exam Description

Topic 2.3, if Statements, 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 language specification defines the two forms of the statement separately, which is why a one-way if with a false condition completes normally without running anything.

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/jls-14.html#jls-14.9

Submit Assignment

Click to upload or drag and drop
PDF, ZIP, images, documents, or Jupyter notebooks (.ipynb) (Max 10MB per file)

Need to update a submission later? Open the submissions dashboard.