Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using python Three Designs for an Account class Design a class called Account wi

ID: 3801518 • Letter: U

Question

using python

Three Designs for an Account class Design a class called Account with the following methods: +Constructor (tmpAcctNum, tmpBankName, tmpAcctType, and tmpBalance):void _str_(): str Description: prints the information for the account one item per line. For example: Account #: 100 Bank: NorWest Account Type: Checking Balance: $150.98 computeInterest():float-should update the balance AND return the amount of interest. getters/setters for each of these: accountNum, bankName, account Type, balance 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. 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. Suggestion: Create 3 modules for the 3 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 3 versions, except that you'll use a different import statement for each.

Explanation / Answer

VERSION :1

#!/usr/bin/python

class Account:

def __init__(self,tmpAcctNum, tmpBankName, tmpAcctType , tmpBalance):
       self.details = []
       self.details.append(tmpAcctNum)
self.details.append(tmpBankName)
self.details.append(tmpAcctType)
self.details.append(tmpBalance)

def __str__(self):
st = ""
st = "Account #: " + str(self.details[0]) + " "
st = st + "Bank: " + self.details[1] + " "
st = st + "Account Type: " + self.details[2] + " "
st = st + "Balance: " + str(self.details[3]) + " "
return st

   def getaccountNum(self):
       return self.details[0]
      
   def getbankName(self):
       return self.details[1]
      
   def getaccountType(self):
       return self.details[2]
          
   def getbalance(self):
       return self.details[3]
          
   def setaccountNum(self, tmpAcctNum):
       self.details.remove(self.details[0])
       self.details.insert(0, tmpAcctNum)
      
   def setbankName(self, tmpBankName):
       self.details.remove(self.details[1])
       self.details.insert(1, tmpBankName)
      
   def setaccountType(self, tmpAcctType):
       self.details.remove(self.details[2])
       self.details.insert(2, tmpAcctType)
          
   def setbalance(self, tmpBalance):
       self.details.remove(self.details[3])
       self.details.insert(3, tmpBalance)      

   #Calculating the simple interest
   def computeInterest(self, timeInYears , rate):
       interest = (self.details[3] * timeInYears * rate) / float(100)
       self.details[3] = self.details[3] + interest
       return interest

VERSION 2 :

#!/usr/bin/python

class Account:

def __init__(self,tmpAcctNum, tmpBankName, tmpAcctType , tmpBalance):
self.accountNum = tmpAcctNum
self.bankName = tmpBankName
self.accountType = tmpAcctType
self.balance = tmpBalance

def __str__(self):
st = ""
st = "Account #: " + str(self.accountNum) + " "
st = st + "Bank: " + self.bankName + " "
st = st + "Account Type: " + self.accountType + " "
st = st + "Balance: " + str(self.balance) + " "
return st

   def getaccountNum(self):
       return self.accountNum
      
   def getbankName(self):
       return self.bankName
      
   def getaccountType(self):
       return self.accountType
          
   def getbalance(self):
       return self.balance
          
   def setaccountNum(self, tmpAcctNum):
       self.accountNum = tmpAcctNum
      
   def setbankName(self, tmpBankName):
       self.bankName = tmpBankName
      
   def setaccountType(self, tmpAcctType):
       self.accountType = tmpAcctType
          
   def setbalance(self, tmpBalance):
       self.balance = tmpBalance      

   #Calculating the simple interest
   def computeInterest(self, timeInYears , rate):
       interest = (self.balance * timeInYears * rate) / float(100)
       self.balance = self.balance + interest
       return interest

VERSION 3 :

#!/usr/bin/python

class Account:

def __init__(self,tmpAcctNum, tmpBankName, tmpAcctType , tmpBalance):
       self.details = (tmpAcctNum, tmpBankName, tmpAcctType, tmpBalance)

def __str__(self):
st = ""
st = "Account #: " + str(self.details[0]) + " "
st = st + "Bank: " + self.details[1] + " "
st = st + "Account Type: " + self.details[2] + " "
st = st + "Balance: " + str(self.details[3]) + " "
return st

   def getaccountNum(self):
       return self.details[0]
      
   def getbankName(self):
       return self.details[1]
      
   def getaccountType(self):
       return self.details[2]
          
   def getbalance(self):
       return self.details[3]
          
   def setaccountNum(self, tmpAcctNum):
       tmpDetails = (tmpAcctNum, self.details[1], self.details[2], self.details[3])
       self.details = tmpDetails

  
   def setbankName(self, tmpBankName):
       tmpDetails = (self.details[0], tmpBankName, self.details[2], self.details[3])
       self.details = tmpDetails
      
   def setaccountType(self, tmpAcctType):
       tmpDetails = (self.details[0], self.details[1], tmpAcctType, self.details[3])
       self.details = tmpDetails
          
   def setbalance(self, tmpBalance):
       tmpDetails = (self.details[0], self.details[1], self.details[2], tmpBalance)
       self.details = tmpDetails

   #Calculating the simple interest
   def computeInterest(self, timeInYears , rate):
       interest = (self.details[3] * timeInYears * rate) / float(100)
       tmpDetails = (self.details[0], self.details[1], self.details[2], self.details[3] + interest)
       self.details = tmpDetails
       return interest

SAMPLE CODE :

act = Account(1011, "SBI" , "Savings", 10002.1)
act.setbalance(10223.2)
act.setaccountNum(10223)

act.setbankName("BOA")
act.computeInterest(2,3)

print act