Bank Account
Level: Intermediate 30–60 minConcepts: StateValidationEdge CasesBoundaries
Create a bank account that tracks transactions and enforces business rules.
Requirements
- Open Account — create an account with an initial balance of 0
- Deposit — add funds to the account
- Amount must be positive
- Records the transaction with date and amount
- 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
- Get Balance — returns the current balance
- 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
| Action | Amount | Expected Balance | Notes |
|---|---|---|---|
| Deposit | 500 | 500 | |
| Deposit | 200 | 700 | |
| Withdraw | 100 | 600 | |
| Withdraw | 700 | 600 | Rejected — insufficient funds |
| Deposit | -50 | 600 | Rejected — negative amount |
| Withdraw | -50 | 600 | Rejected — negative amount |
| Deposit | 0 | 600 | Rejected — 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