01
Overview

A class whose methods branch on conditions.

Combine class structure with if/else logic across multiple methods to build full behavior.

Real classes have multiple methods that make decisions: a setter that validates, a behavior method that branches by state, a calculator that handles tiers. The combination produces interesting, testable behavior.

On the AP exam, conditional-logic class FRQs test both class structure AND the if/else logic inside the methods.

02
Core Concept

Each method has its own decision structure.

Mutators validate; behaviors classify.

TrafficLight example

public class TrafficLight {
    private String color;   // "red", "yellow", or "green"

    public TrafficLight() { color = "red"; }

    public String getColor() { return color; }

    public void next() {
        if (color.equals("red")) color = "green";
        else if (color.equals("green")) color = "yellow";
        else color = "red";
    }

    public boolean canCross() {
        return color.equals("green");
    }

    public int timeToWait() {
        if (color.equals("green")) return 0;
        else if (color.equals("yellow")) return 5;
        else return 30;
    }
}

Three behavior methods, three branching structures, all using the same state.

Why methods compose well

Each method does one thing: next changes state; canCross reports a yes/no; timeToWait returns a number. They share the field but stay independent. Test each in isolation.

03
Key Vocabulary

Conditional class vocabulary.

Used in stateful class FRQs.

Vocabulary
  • Branching method — uses if/else to choose behavior.
  • State-dependent — output depends on current field values.
  • Boolean accessor — returns true/false based on state.
  • Tiered return — different value per state.
  • State transition — moving from one state to another.
04
AP Exam Focus

How conditional classes are tested.

Each method needs its own logic check.

Exam Focus
  • Use .equals() for String comparison.
  • Cover all branches. Especially the final else.
  • Match return types per spec. boolean, int, String, etc.
  • State changes only in mutators. Accessors don't modify.
05
Worked Example

Cycle a TrafficLight.

State transitions and behavior responses.

Worked Example AP-style reasoning

Setup. TrafficLight t = new TrafficLight(); — starts red.

  • t.canCross() → false (color is red).
  • t.timeToWait() → 30.
  • t.next() → color = green.
  • t.canCross() → true.
  • t.next() → color = yellow.
  • t.timeToWait() → 5.
  • t.next() → color = red.
06
Common Mistakes

Branching-method pitfalls.

Mostly String comparison and missing branches.

Watch Out
  • == on Strings. Use .equals().
  • Missing else. Method may not return on all paths.
  • Tied output for different states. Each branch should be distinct.
  • Behavior method mutating state. Keep concerns separated.
07
Reference Table

Method roles.

Mutate vs query.

Conditional Class Reference

AP Quick Reference
Method typeReads stateWrites state
Mutator (next)YesYes
Boolean query (canCross)YesNo
Numeric query (timeToWait)YesNo
08
Practice Tip

How to master conditional classes.

Each method gets its own if/else block.

Practice Strategy
  • MCQ Practice — verify each method covers all states.
  • Java Lab — build TrafficLight, ElevatorDoor, Mode classes.
  • FRQ Practice — split mutators from queries; one branching block per method.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 19 marks Pending

AP CSA Unit 13 Topic 04 Complete Class with Conditional Logic FRQ Practice

AP-style topic practice assessment

Start