Bank Account System - Problem
Design a bank account system using object-oriented programming principles. Implement three classes: Account, SavingsAccount, and CheckingAccount.
The system should support the following operations:
- deposit(amount): Add money to the account
- withdraw(amount): Remove money from the account (if sufficient balance)
- transfer(amount, targetAccount): Transfer money between accounts
- getBalance(): Get current account balance
Each account has a unique account number and tracks its balance. The SavingsAccount has a minimum balance requirement, while CheckingAccount allows overdrafts up to a limit.
Given a series of operations, return the final state of all accounts as a JSON object.
Input & Output
Example 1 — Basic Account Operations
$
Input:
operations = [{"type":"create","accountNumber":"ACC001","accountType":"savings","initialBalance":1000,"minBalance":100},{"type":"deposit","accountNumber":"ACC001","amount":200},{"type":"withdraw","accountNumber":"ACC001","amount":50}]
›
Output:
{"ACC001":{"type":"savings","balance":1150}}
💡 Note:
Create savings account with $1000, deposit $200 (balance = $1200), withdraw $50 (balance = $1150). Withdrawal allowed since $1150 > $100 minimum.
Example 2 — Transfer Between Accounts
$
Input:
operations = [{"type":"create","accountNumber":"ACC001","accountType":"savings","initialBalance":1000},{"type":"create","accountNumber":"ACC002","accountType":"checking","initialBalance":500},{"type":"transfer","fromAccount":"ACC001","toAccount":"ACC002","amount":200}]
›
Output:
{"ACC001":{"type":"savings","balance":800},"ACC002":{"type":"checking","balance":700}}
💡 Note:
Transfer $200 from savings to checking. Both accounts updated: savings $1000→$800, checking $500→$700.
Example 3 — Minimum Balance Constraint
$
Input:
operations = [{"type":"create","accountNumber":"ACC001","accountType":"savings","initialBalance":150,"minBalance":100},{"type":"withdraw","accountNumber":"ACC001","amount":60}]
›
Output:
{"ACC001":{"type":"savings","balance":150}}
💡 Note:
Withdrawal of $60 denied because $150-$60=$90 would be below $100 minimum balance. Balance remains $150.
Constraints
- 1 ≤ operations.length ≤ 1000
- Account numbers are unique strings
- All monetary amounts are non-negative numbers
- Minimum balance for savings accounts ≥ 0
- Overdraft limit for checking accounts ≥ 0
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code