Bank Accounts
Imagine that you are a software engineer at a top-tier bank. The bank is working to improve their backend system, and your task is to design and implement new classes to represent different types of bank accounts.
The bank offers two types of accounts: checking and savings. Both types of accounts allow customers to deposit and withdraw money. But each type of account has its own characteristics. Checking accounts have an overdraft limit, which allows customers to withdraw money beyond their current balance up to the overdraft limit. Savings accounts earn interest based on an annual percentage yield.
Your task is to create three Python classes: BankAccount, CheckingAccount, and SavingsAccount. All of them are initialized with a starting balance amount.
The
BankAccountclass should have two methods:depositandwithdraw. Thedepositmethod should increase the balance by the amount of the deposit. Thewithdrawmethod should decrease the balance by the amount of the withdrawal. Both should print the final balance after the operation in theBalance: <X>format. If there aren’t sufficient funds, the program should printInsufficient funds..The
CheckingAccountclass should inherit fromBankAccountand add an additional attribute:overdraft_limit. Thewithdrawmethod inCheckingAccountshould be overridden to allow customers to withdraw money beyond their current balance up to the overdraft limit. In case of exceeding the overdraft limit, the program should printWithdrawal exceeds overdraft limit..The
SavingsAccountclass should also inherit fromBankAccount. It should add an additional initialization attribute:annual_percentage_yield, and add a methodcalculate_returnsthat calculates the returns for saving money based on theannual_percentage_yield. Thecalculate_returnsmethod should print the returns in theReturns: Xformat.
The balance in any account should never become negative (except for the CheckingAccount where it can go up to the negative overdraft limit).
Input | Output |
|---|---|
| Balance: 700 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB