Question: This is done in PYTHON. I need to finish the TODO which is adding the __repr__ to the end of each class and finishing TimeDepositAccount
This is done in PYTHON. I need to finish the TODO which is adding the __repr__ to the end of each class and finishing TimeDepositAccount class. Below I will include the UML diagram

Below is the expected output for the given tester:
Test with Penalty
Before withdrawal ($500): 1000.29
After withdrawal ($500): 490.28999999999996
Test without Penalty
Before withdrawal ($500): 1000.5800840999999
After withdrawal ($500): 500.5800840999999
SavingsAccount[balance=10025.0]
CheckingAccount[balance=125.0]
TimeDepositAccount[balance=515.29][monthsToMaturity=1]
TimeDepositAccount[balance=525.5800840999999] [monthsToMaturity=0]
##
# This module defines several classes that implement a banking account
# class hierarchy.
#
## A bank account has a balance and a mechanism for applying interest or fees at
# the end of the month.
#
class BankAccount :
## Constructs a bank account with zero balance.
#
def __init__(self) :
self._balance = 0.0
## Makes a deposit into this account.
# @param amount the amount of the deposit
#
def deposit(self, amount) :
self._balance = self._balance + amount
## Makes a withdrawal from this account, or charges a penalty if
# sufficient funds are not available.
# @param amount the amount of the withdrawal
#
def withdraw(self, amount) :
self._balance = self._balance - amount
## Carries out the end of month processing that is appropriate
# for this account.
#
def monthEnd(self) :
return
## Gets the current balance of this bank account.
# @return the current balance
#
def getBalance(self) :
return self._balance
## TODO: __repr__
## A savings account earns interest on the minimum balance.
#
class SavingsAccount(BankAccount) :
## Constructs a savings account with a zero balance.
#
def __init__(self) :
super().__init__()
self._interestRate = 0.0
self._minBalance = 0.0
## Sets the interest rate for this account.
# @param rate the monthly interest rate in percent
#
def setInterestRate(self, rate) :
self._interestRate = rate
## Overrides superclass method.
#
def withdraw(self, amount) :
super().withdraw(amount)
balance = self.getBalance()
if balance
self._minBalance = balance
## Overrides superclass method.
#
def monthEnd(self) :
interest = self._minBalance * self._interestRate / 100
self.deposit(interest)
self._minBalance = self.getBalance()
## TODO: __repr__
## A checking account has a limited number of free deposits and withdrawals.
#
class CheckingAccount(BankAccount) :
## Constructs a checking account with a zero balance.
#
def __init__(self) :
super().__init__()
self._withdrawals = 0
## Overrides superclass method.
#
def withdraw(self, amount) :
FREE_WITHDRAWALS = 3
WITHDRAWAL_FEE = 1
super().withdraw(amount)
self._withdrawals = self._withdrawals + 1
if self._withdrawals > FREE_WITHDRAWALS :
super().withdraw(WITHDRAWAL_FEE)
## Overrides superclass method.
#
def monthEnd(self) :
self._withdrawals = 0
## TODO: __repr__
## TODO: TimeDepositAccount class
class TimeDepoistAccount (BankAccount)
def __init__(self) :
def setMonthsToMaturity(self, months)
def withdraw(self, amount)
def monthEnd(self)
def __repr__(self):
# ACO 240 Using SavingsAccount and CheckingAccount for How To 10.1 Python for Everyone
# Tester code
mySavings = SavingsAccount()
mySavings.deposit(10000)
mySavings.setInterestRate(.015)
myChecking = CheckingAccount()
myChecking.deposit(100)
print("Test with Penalty")
tda1 = TimeDepositAccount()
tda1.deposit(1000)
tda1.setInterestRate(.029)
tda1.setMonthsToMaturity(3)
tda1.monthEnd() # month 1
tda1.monthEnd() # month 2
print("Before withdrawal ($500): ", tda1.getBalance())
tda1.withdraw(500)
print("After withdrawal ($500): ", tda1.getBalance())
print("Test without Penalty")
tda2 = TimeDepositAccount()
tda2.deposit(1000)
tda2.setInterestRate(.029)
tda2.setMonthsToMaturity(3)
tda2.monthEnd() # month 1
tda2.monthEnd() # month 2
tda2.monthEnd() # month 2
print("Before withdrawal ($500): ", tda2.getBalance())
tda2.withdraw(500)
print("After withdrawal ($500): ", tda2.getBalance())
# Quarterly Bonus: For all accounts, give customer $25 bonus and display accounts
accts = [mySavings, myChecking, tda1, tda2]
for a in accts:
a.deposit(25)
print(a)
> BankAccount _balance: float _init__(self) deposit(self, amount) withdraw(self, amount) month End(self) getBalance(self): float _repr_(self) A Savings Account _interestRate: float _minBalance: float _init__(self) setinterestRate(self, rate) with draw(self, amount) month End(self) repr_(self) Checking Account _withdrawals int _init__(self) withdraw(self, amount) month End(self) _repr_(self) TimeDeposit Account _monthsToMaturity int EARLY_WITHDRAWAL: int _init__(self) setMonthsToMaturity(self, months) withdraw(self, amount) month End(self) repr (self) > BankAccount _balance: float _init__(self) deposit(self, amount) withdraw(self, amount) month End(self) getBalance(self): float _repr_(self) A Savings Account _interestRate: float _minBalance: float _init__(self) setinterestRate(self, rate) with draw(self, amount) month End(self) repr_(self) Checking Account _withdrawals int _init__(self) withdraw(self, amount) month End(self) _repr_(self) TimeDeposit Account _monthsToMaturity int EARLY_WITHDRAWAL: int _init__(self) setMonthsToMaturity(self, months) withdraw(self, amount) month End(self) repr (self)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
