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

This question tests your understanding of Object Oriented Programming. The follo

ID: 3816109 • 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 balance (the interest should be the interest rate multiplied by the current balance). (c) Create a subclass of BankAccount called StudentAccount. 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

aAns: Class variable in the code is

1.interesr_rate

Instance variable in the code are:

1. name

2. number

3. balance

bAns::

class BankAccount(object):

# interest rate

interest_rate = 0.4

MIN_BALANCE = 0 # min bal set to 0

def __init__(self, name, number, balance):

self.name = name

self.number = number

self.balance = balance

return

#deposit method

def deposit(self, amount):

self.balance += amount

print ("you are successfully deposited_amount %d." % (amount))

print("your current balance is = %d" % (self.balance))

# withdraw method

def withdraw(self, amount):

if (self.balance - amount) > self.MIN_BALANCE: # if doesn't overdraft

self.balance -= amount

print ("you successfully withdrawn your amount %d." % (amount))

print("Current balance = %d" % (self.balance))

else:

print("There is no enough balance in your account!")

# interest method

def add_interest(self):

self.balance = self.balance + (self.balance * self.interest_rate)

print("you succesfully added interest to the account")

print("Current balance = %d" % (self.balance))

cANS::

class StudentAccount(BankAccount):

def __init__(self, name,number, balance):

#bank acc init, self_name_numbr_bal

BankAccount.__init__(self, name, number, balance)

# withdraw

def withdraw(self, amt):

# greater than 1000

if self.balance – amt > 1000:

self.balance -= amt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote