Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” Classes

โญ beginnerโณ 20 min read๐Ÿ“ Lesson 37 of 85

A bank account: an owner, a balance, and two doors โ€” every mutation validated, every invariant testable.

Checkpoint: the bank account

Task: implement nested class Solution.BankAccount:

  1. Constructor (string owner, decimal openingBalance) โ€” throws ArgumentException for a null/whitespace owner or a negative opening balance.
  2. Read-only Owner and Balance properties.
  3. Deposit(decimal amount) โ€” throws ArgumentException unless amount > 0; otherwise adds to the balance.
  4. Withdraw(decimal amount) โ€” throws ArgumentException unless amount > 0, throws InvalidOperationException when funds are insufficient; otherwise subtracts.

The invariant: the balance only ever changes through positive, funded operations. A rejected operation must leave the balance exactly as it was.