Hi Please see question below It is an OOB question in the Py

Hi, Please see question below. It is an OOB question in the Python language. I would be grateful for any help with this 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 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.

Solution

class BankAccount(object):

interest_rate = 0.3
def __init__(self, name, number, balance):
self.name = name
self.number = number
self.balance = balance
return

def deposit(self,amount):
   self.balance = self.balance+amount
   print \"New balance is \",self.balance


def withdraw(self,amount):

    if self.balance <amount:
        print \"balance is low\"
    else:
        self.balance=self.balance-amount
def interest():
    self.balance=self.balance+self.balance*interest_rate/100

class StudentAccount(BankAccount):
   limit=1000

   def __init__(self, name, number, balance):
       super(StudentAccount,self).__init__(name, number, balance)
       return

   def withdraw(self,amount):

       if amount < 1000:
           if self.balance <amount:
                print \"balance is low\"
            else:
                self.balance=self.balance-amount
        else:
            print \"Cannot remove more than 1000\"

BO=BankAccount(\"Akshay\",123,1000)
BO.deposit(100)

SO=StudentAccount(\"Raj\",13,10000)
SO.withdraw(2000)
       
      


  
  


===========================================================

Output:

Akshay@akshay-Inspiron-3537:~/Chegg$ python bank.py
New balance is 1100
Cannot remove more than 1000

Hi, Please see question below. It is an OOB question in the Python language. I would be grateful for any help with this question. This question tests your under
Hi, Please see question below. It is an OOB question in the Python language. I would be grateful for any help with this question. This question tests your under

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site