using python 3 \'\'\'\'\' Program 13: Inheritance 20 pts Design the Account clas
ID: 3816051 • Letter: U
Question
using python 3
'''''
Program 13: Inheritance 20 pts Design the Account class using the UML shown below: Account -lastAcctNumUsed: integer (initialize to 100 make it a class-level attribute acct Num: integer -bankName string NOTE: checking, savings, genera l -acct Type:string -opening Balance: float currentBalance float -dateopened: date Constructor >Account (tmpBankName: string, tmpopen Bal float, dateopened:date) NOTES: Set currentBalance to same amt as tmpopen Bal Use the class-level variable to determine the account number Account type should be assigned as "general" +toString String Description returns a string containing the information for the account, la beling each item Make sure to format the currency items appropriately Format the date as mm/dd/yy +getAcctNum nteger +getbank Name() string +getopening Balance(): float +getacctType string +getCurrent Balance float +getDateopened() date Design a test program for ALL methods in this class called testAccount.py Create class CheckingAcct (inherits attributes & methods from the Account class) CheckingAcct -totalDeposits: float -totalWithdrawals: floatExplanation / Answer
Answer:
Note: With the provided time, I completed upto SavingsAcct.py alone.
Code:
#Account.py
class Account:
lastAcctNumUsed=100
def __init__(self,tmpBankName, tmpOpenBal, dateOpened):
self.acctNum = Account.lastAcctNumUsed
self.bankName=tmpBankName
self.acctType='general'
self.openingBalance = tmpOpenBal
self.currentBalance = tmpOpenBal
self.dateOpened=dateOpened
def toString(self):
myStr='';
myStr += "Account Number:"+str(self.acctNum)+" "
myStr += "Bank Name:"+self.bankName+" "
myStr += "Account Type:"+self.acctType+" "
myStr += "Opening Balance: $"+str(self.openingBalance)+" "
myStr += "Current Balance: $"+ str(self.currentBalance)+" "
myStr += "Account opened Date:"+self.dateOpened.strftime("%m/%d/%y")
return myStr
def getAcctNum(self):
return self.acctNum
def getbankName(self):
return self.bankName
def getacctType(self):
return self.acctType
def getOpeningBalance(self):
return self.openingBalance
def getCurrentBalance(self):
return self.currentBalance
def getDateOpened(self):
return self.dateOpened
#testAccount.py
from Account import Account
import datetime
p=Account('Own Bank',8000,datetime.date.today())
print("Account Number: ")
print(str(p.getAcctNum()))
print("Bank Name: ")
print(p.getbankName())
print("Account Type: ")
print(p.getacctType())
print("Opening Balance: ")
print("$"+str(p.getOpeningBalance()))
print("Current Balance: ")
print("$"+str(p.getCurrentBalance()))
print(" My Account details:")
myStrr=p.toString()
print (myStrr)
sample output:
Account Number:
100
Bank Name:
Own Bank
Account Type:
general
Opening Balance:
$8000
Current Balance:
$8000
My Account details:
Account Number:100
Bank Name:Own Bank
Account Type:general
Opening Balance: $8000
Current Balance: $8000
Account opened Date:04/12/17
#CheckingAccount.py
from Account import Account
class CheckingAcct(Account):
def __init__(self,tmpBankName, tmpOpenBal, dateOpened):
Account.lastAcctNumUsed=200
self.acctNum=Account.lastAcctNumUsed
Account.__init__(self,tmpBankName, tmpOpenBal, dateOpened)
self.acctType="Checking"
self.totalDeposits =0
self.totalWithdrawals=0
def deposit(self,amt):
self.totalDeposits += 1
self.currentBalance += amt
def withdrawal(self,amt):
myStrr=""
if(self.currentBalance>amt):
self.totalWithdrawals += 1
self.currentBalance -= amt
myStrr = "Successfully withdrawal"
else:
myStrr = "Overdrafts not allowed"
return myStrr
def toString(self):
myStrr=Account.toString(self)
myStrr+= " Total Deposits:"+str(self.totalDeposits)+" "
myStrr += "Total Withdrawals:"+str(self.totalWithdrawals)
return myStrr
#testCheckingAcct.py
from CheckingAcct import CheckingAcct
import datetime
ch=CheckingAcct('Bank',4000,datetime.date.today())
print(" My Account details:")
myStrr=ch.toString()
print (myStrr)
ch.deposit(400)
print(" After depositing $400:")
myStrr=ch.toString()
print (myStrr)
ch.withdrawal(1000)
print(" After withdrawal of $1000:")
myStrr=ch.toString()
print (myStrr)
sample output:
My Account details:
Account Number:200
Bank Name:Bank
Account Type:Checking
Opening Balance: $4000
Current Balance: $4000
Account opened Date:04/12/17
Total Deposits:0
Total Withdrawals:0
After depositing $400:
Account Number:200
Bank Name:Bank
Account Type:Checking
Opening Balance: $4000
Current Balance: $4400
Account opened Date:04/12/17
Total Deposits:1
Total Withdrawals:0
After withdrawal of $1000:
Account Number:200
Bank Name:Bank
Account Type:Checking
Opening Balance: $4000
Current Balance: $3400
Account opened Date:04/12/17
Total Deposits:1
Total Withdrawals:1
#SavingsAcct.py
from Account import Account
from datetime import datetime
class SavingsAcct(Account):
def __init__(self,tmpBankName, tmpOpenBal,dateOpened, maturityDate, intRate):
Account.lastAcctNumUsed=300
self.acctNum=Account.lastAcctNumUsed
Account.__init__(tmpBankName, tmpOpenBal, dateOpened)
self.maturityDate =maturityDate
self.acctType="Savings"
self.interestRate=intRate
self.totalInterestearned = 0
self.lastDateInterestAdded =dateOpened
def computeInterest(tmpDate):
m1=datetime.strptime(self.lastDateInterestAdded,"%Y-%m-%d")
m2=datetime.strptime(datetime.date.today(),"%Y-%m-%d")
diff=abs((m2-m1).days)
if(diff>=30):
extra = self.currentBalance * self.intRate
self.currentBalance += extra
self.totalInterestearned += extra
self.lastDateInterestAdded = datetime.date.today()
def toString(self):
myStrr=Account.toString(self)
myStrr+= " Maturity Date:"+self.maturityDate.strftime("%m/%d/%y")+" "
myStrr += "Interest Rate:"+str(self.intRate)+" "
myStrr += "Total Interest Earned:"+str(self.totalInterestEarned)+" "
myStrr += "Last Date Interest Added:"+self.lastDateInterestAdded.strftime("%m/%d/%y")
return myStrr
def closeAcct(self, d):
myStrr=""
m1=datetime.strptime(self.maturityDate,"%Y-%m-%d")
m2=datetime.strptime(d,"%Y-%m-%d")
diff=((m2-m1).days)
if(diff<=0):
myStrr = "Successfully closed"
else:
myStrr="Cannot close"
return myStrr
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.