In: Computer Science
Using python class:
Design a class called Account
CLASS NAME: Account |
ATTRIBUTES: -nextAcctID: int #NOTE- class-level attribute initialized to 1000 -acctID: int |
METHODS: <<Constructor>>Account(id:int, bank: String,
type:String, bal:float) +getBalance(void): float +str(void): String NOTE: Description: prints the
information for the account one item per line. For example: +calcInterest(type):float |
Version 1 of the Account class: private data is
a list that stores the account number, bank name,
account type, and balance.
Version2 of the Account class: private data is
stored as separate variables.
OPTIONAL BONUS + 5: Version 3 of the Account class: private data is stored as a tuple that stores the account number, bank name, account type, and balance.
Create a test program that works with all versions of the Account class, regardless of the way the private data was stored in the class. LABEL all output, and be SURE to test EVERY method!
Suggestion:
Create separate modules for each of the different versions of
the Account class.
Be sure that the class itself is always called
Account in each of the modules – only the module name
should change.Your testing should provide the SAME code for ALL
versions, except that you’ll use a different import statement for
each.
###### Account type-1 ####################
class Account:
nextAcctID=1000
def __init__(self, list,acctID, bank,acctType,balance):
self.list=list
self.list.append(acctID)
self.list.append(bank)
self.list.append(acctType)
self.list.append(balance)
def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
self.list[0]=newID
def getBank(self):
return self.list[1]
def setBank(self,newBank):
self.list[1]=newBank
def getBalance(self):
return self.list[3]
def setBalance(self,newBal):
self.list[3]=newBal
def str(self):
print("Account#: %d" %(self.list[0]))
print("Bank: %s" %(self.list[1]))
print("Account type: %s" %(self.list[2]))
print("Balance: $%.2f" %(self.list[3]))
def calcInterest(self):
if(self.list[2]=="checking"):
interest=self.list[3]*0.01
self.list[3]=self.list[3]+interest
if(self.list[2]=="savings"):
interest=self.list[3]*0.02
self.list[3]=self.list[3]+interest
list=[]
a1 = Account(list,100,"UTI","savings",300.5)
a1.str()
a1.calcInterest()
a1.str()
###### enf of Account type-1 ####################
###### Account type-2 ####################
class Account:
nextAcctID=1000
def __init__(self, acctID, bank,acctType,balance):
self.acctID=acctID
self.bank=bank
self.acctType=acctType
self.balance=balance
def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
self.acctID=newID
def getBank(self):
return self.bank
def setBank(self,newBank):
self.bank=newBank
def getBalance(self):
return self.balance
def setBalance(self,newBal):
self.balance=newBal
def str(self):
print("Account#: %d" %(self.acctID))
print("Bank: %s" %(self.bank))
print("Account type: %s" %(self.acctType))
print("Balance: $%.2f" %(self.balance))
def calcInterest(self):
if(self.acctType=="checking"):
interest=self.balance*0.01
self.balance=self.balance+interest
if(self.acctType=="savings"):
interest=self.balance*0.02
self.balance=self.balance+interest
a1 = Account(100,"UTI","savings",300.5)
a1.str()
a1.calcInterest()
a1.str()
###### end of Account type-2 ####################
###### Account type-3 ####################
class Account:
nextAcctID=1000
def __init__(self, record,acctID, bank,acctType,balance):
self.record=record
recordList=list(self.record)
recordList.append(acctID)
recordList.append(bank)
recordList.append(acctType)
recordList.append(balance)
self.record=tuple(recordList)
def getAcctID(self):
return self.nextAcctID
def setAcctID(self,newID):
recordList=list(self.record)
recordList[0]=newID
self.record=tuple(recordList)
def getBank(self):
return self.record[1]
def setBank(self,newBank):
recordList=list(self.record)
recordList[1]=newBank
self.record=tuple(recordList)
def getBalance(self):
return self.record[3]
def setBalance(self,newBal):
recordList=list(self.record)
recordList[3]=newBal
self.record=tuple(recordList)
def str(self):
print("Account#: %d" %(self.record[0]))
print("Bank: %s" %(self.record[1]))
print("Account type: %s" %(self.record[2]))
print("Balance: $%.2f" %(self.record[3]))
def calcInterest(self):
if(self.record[2]=="checking"):
interest=self.record[3]*0.01
recordList=list(self.record)
recordList[3]=recordList[3]+interest
self.record=tuple(recordList)
if(self.record[2]=="savings"):
interest=self.record[3]*0.02
recordList=list(self.record)
recordList[3]=recordList[3]+interest
self.record=tuple(recordList)
record=()
a1 = Account(record,100,"UTI","savings",3000.5)
a1.str()
a1.calcInterest()
a1.str()
## end of Account type-3 #####################