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

You are upgrading the ATM system of the previous problem using a new object-orie

ID: 3843669 • Letter: Y

Question


You are upgrading the ATM system of the previous problem using a new object-oriented design. You must create a Python class, SavingsAccount, whose objects have the following instance variables: accountNumber, customerName and balance. Write the constructor method, init (self, acctNum acctName, acctBal) which creates an account with the given values for the instance variables. Also write methods getBalance (self), which returns the balance of an account, deposit (self, amt), which increases the balance by amt, and withdraw (self, amt), which decreases the account balance by amt. Assume the balance, deposit, and withdrawal amounts are all in cents (integers).

Explanation / Answer

The code is as follows:

#!/usr/bin/python

class SavingAccount:
      accountNumber = 1
      customerName = ""
      balance = 1

      def __init__(self, acctNum, acctName, acctBal):
          self.accountNumber = acctNum
          self.customerName = acctName
          self.balance = acctBal

      def getBalance(self):
          return self.balance

      def deposit(self, amt):
          self.balance = self.balance + amt

      def withdrawl(self, amt):
          self.balance = self.balance - amt

ab = SavingAccount(123, "xyz", 100)
print ab.getBalance()
ab.deposit(200)
print ab.getBalance()
ab.withdrawl(100)
print ab.getBalance()

    

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