This question tests your understanding of Object Oriented Programming. The follo
ID: 3833408 • Letter: T
Question
This question tests your understanding of Object Oriented Programming. The following code defines the start of a class to represent bank accounts: class BankAccount (object): interest _rate = 0.3 def _init_(self, name, number balance): self.name = name self.number = number self.balance = balance return (a) Name the class variables and the instance variables in the given code. (b) Add instance methods called deposit() and withdraw() which increase and decrease the balance of the account. Make sure the withdraw() method doesn't allow the account to go into overdraft. Add a third method called add_interest() which adds interest to the balance (the interest should be the interest rate multiplied by the current balance. (c) Create a subclass of BankAccount called Student Account. Every StudentAccount should have an overdraft limit of 1000. Write a constructor for the new class. Override the withdraw() method to make sure that students can withdraw money up to their overdraft limits.Explanation / Answer
a)
class variables - interest_rate
instance variable - name, number, balance
b) class BankAccount(object):
interest_rate = 0.3
def __init__(self, name, number, balance):
self.name = name
self.number = number
self.balance = balance
return;
def withdraw(self, amount):
if(amount<balance):
balance = balance - amount
def deposit(self, amount):
balance = balance + amount
def add_interest():
balance = balance + (balance*interest_rate)
c) class StudentAccount(BankAccount):
def __init__(self, name, number, balance):
BankAccount.__init__(self, name, number, balance)
def withdraw(self, amount):
if((balance-amount)>=-1000):
balance = balance - amount
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.