Reference no: EM132361108
Question
Define Customer class. A customer has a first name, last name, and social security number. You must override __str__ operator to return the customer first name, last name and ssn.
Define a BankAccount base class. A BankAccount has a customer, account number, and a balance. A bank account can be opened with any amount of initial deposit.
For each bank account, a 10 digit random account number must be created.
Bank account has the following methods: deposit, withdraw. applyAnnualInterest.
Note that the amount withdrawn cannot exceed the balance. If it does, the amount should not be withdrawn and insufficient funds should be reported.
You must override __str__ operator to return a pretty string representation of a bank account.
You shall define two types of account subclasses: Checking Account and Saving Account.
These subclasses inherit from the BankAccount base class.
Each account accrues interest. A saving account accrues 5% fixed interest and a checking account accrues 2% for any amount in excess of $10000 (For example, if there is $11000 in the checking account, the interest is only applied to $1000).
The "main" shown below can be used to test the application. The expected output is also provided.
def main():
alin = Customer('Alin', 'Smith', '111-11-1111')
mary = Customer('Mary', 'Lee', '222-22-2222')
alinAccnt = CheckingAccount(alin)
maryAccnt = SavingAccount(mary)
alinAccnt.deposit(20000)
print(alinAccnt)
alinAccnt.withdraw(5000)
print(alinAccnt)
alinAccnt.applyAnnualInterest()
print(alinAccnt)
maryAccnt.deposit(10000)
print(maryAccnt)
maryAccnt.withdraw(15000)
print(maryAccnt)
maryAccnt.applyAnnualInterest()
print(maryAccnt)
=================== This is the expected output =======================
Alin Smith (ssn: 111-11-1111) , account number 1702660396, balance $20000
Alin Smith (ssn: 111-11-1111) , account number 1702660396, balance $15000
Alin Smith (ssn: 111-11-1111) , account number 1702660396, balance $15100.0
Mary Lee (ssn: 222-22-2222) , account number 2552619508, balance $10000
Mary Lee (ssn: 222-22-2222) , insufficent funds to withdraw $ 15000
Mary Lee (ssn: 222-22-2222) , account number 2552619508, balance $10000
Mary Lee (ssn: 222-22-2222) , account number 2552619508, balance $10500.0
You have coded it as below but I'm having trouble trying to test the below code and get above output. Please review your code and let you know how you can test the below code to get the above expected output?
class Customer:
def __init__(self,firstName, lastName, ssn):
self.firstName = firstName
self.lastName = lastName
self.ssn = ssn
def setfirstName(self,firstName):
self.firstName = firstName
def setlastName(self,lastName):
self.lastName = lastName
def __str__(self):
self.name = "{},{} (SSN:{})".format(self.firstName, self.lastName,self.ssn)
return self.name
class BankAccount(Customer):
def __init__(self,customer,balance = 0):
from random import randint
n = 10
range_start = 10**(n-1)
range_end = (10**n)-1
accountNumber = randint(range_start, range_end)
self.customer = customer
self.balance = balance
self.accountNumber = randint(self.range_start, self.range_end)
def setCustomer(self,customer,accountNumber):
self.customer = customer
self.accountNumber = accountNumber
def getCustomer(self,customer,accountNumber):
return self.customer, self.accountNumber
def __str__(self):
customer = "{} account number: {}, balance: ${}".format(self.customer,self.accountNumber,self.balance)
return customer