01
Overview

Banking-style operations with guards.

Deposit must reject negative amounts; withdraw must reject overdrafts. Both follow the same guarded-mutator shape.

The BankAccount FRQ is one of the most common AP class designs. The class holds a balance; deposits add to it; withdrawals subtract from it. Both methods guard against invalid input — and return a boolean indicating whether the transaction succeeded.

On the AP exam, this design appears in BankAccount, Wallet, and ResourceTracker FRQs.

02
Core Concept

Validate amount; check balance; update.

Three guards plus a status return.

BankAccount class

public class BankAccount {
    private double balance;

    public BankAccount(double startingBalance) {
        balance = startingBalance;
    }

    public boolean deposit(double amount) {
        if (amount <= 0) return false;
        balance += amount;
        return true;
    }

    public boolean withdraw(double amount) {
        if (amount <= 0) return false;
        if (amount > balance) return false;
        balance -= amount;
        return true;
    }

    public double getBalance() { return balance; }
}

Why two checks on withdraw

  • Amount must be positive (no "withdrawing" negative money).
  • Amount must not exceed balance (no overdraft).

Order of checks

Cheap, simple guards first (amount <= 0); then the more contextual one (amount > balance). Both must pass before the balance updates.

03
Key Vocabulary

Banking vocabulary.

Used in financial-style FRQs.

Vocabulary
  • Deposit — add to the balance.
  • Withdraw — subtract from the balance.
  • Overdraft — withdrawal that exceeds balance.
  • Guard — check that protects state.
  • Status return — boolean reporting success.
04
AP Exam Focus

How banking classes are tested.

Both guards plus status return.

Exam Focus
  • Reject non-positive amounts. Both methods.
  • Reject overdrafts. Withdraw only.
  • Return boolean. True on success.
  • Update balance only after all checks pass.
05
Worked Example

Trace transactions.

Successes and rejections.

Worked Example AP-style reasoning

Setup. BankAccount acc = new BankAccount(100);

  • acc.deposit(50) → true; balance=150.
  • acc.deposit(-20) → false; balance stays 150.
  • acc.withdraw(30) → true; balance=120.
  • acc.withdraw(200) → false (overdraft); balance stays 120.
  • acc.withdraw(0) → false (non-positive).
06
Common Mistakes

Banking-class pitfalls.

Missing guards or wrong order.

Watch Out
  • No positive check on deposit. Negative deposit reduces balance.
  • No overdraft check. Balance goes negative.
  • Updating before checking. Invalid state on rejection.
  • Returning void instead of boolean. Caller can't tell.
07
Reference Table

Banking method shape.

Guards then action.

Banking Reference

AP Quick Reference
MethodGuardsAction
depositamount > 0balance += amount
withdrawamount > 0; amount <= balancebalance -= amount
Returnbooleantrue on success.
08
Practice Tip

How to master banking classes.

Two guards on withdraw; one on deposit.

Practice Strategy
  • MCQ Practice — for each option, verify both guards on withdraw.
  • Java Lab — build BankAccount; test negative deposits and overdrafts.
  • FRQ Practice — checks first, action second, return true at the end.
09
Section · 09

Practice — attempt these now.

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

FRQ Practice 30 min 20 marks Pending

AP CSA Unit 13 Topic 12 Guarded Deposit and Withdraw FRQ Practice

AP-style topic practice assessment

Start