Bank Account

Level: Intermediate 30–60 min

Concepts: StateValidationEdge CasesBoundaries


Create a bank account that tracks transactions and enforces business rules.

Requirements

  1. Open Account — create an account with an initial balance of 0
  2. Deposit — add funds to the account
    • Amount must be positive
    • Records the transaction with date and amount
  3. Withdraw — remove funds from the account
    • Amount must be positive
    • Cannot withdraw more than current balance (no overdraft)
    • Records the transaction with date and amount
  4. Get Balance — returns the current balance
  5. Print Statement — returns a formatted statement showing all transactions

Statement format:

Date       | Amount  | Balance
2026-01-15 |  500.00 |  500.00
2026-01-20 | -100.00 |  400.00
2026-01-25 |  200.00 |  600.00

Transactions are printed in chronological order with running balance.

Test Cases

ActionAmountExpected BalanceNotes
Deposit500500
Deposit200700
Withdraw100600
Withdraw700600Rejected — insufficient funds
Deposit-50600Rejected — negative amount
Withdraw-50600Rejected — negative amount
Deposit0600Rejected — zero amount

Bonus

  • Add transfer between two accounts — atomic operation, both sides must succeed
  • Add overdraft limit — allow withdrawals up to a configurable negative balance
  • Add interest calculation — apply monthly interest based on average daily balance
  • Add transaction categories — tag transactions and filter statements by category