Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #LAB10B bankaccount.py
  2. class BankAccount (object) :
  3.    
  4.     # class constructor
  5.     def __init__(self, acct, num, bal, credit = 2500) :
  6.         self.Holder = acct
  7.         self.Number = num
  8.         self.Balance = bal
  9.         self.LineOfCredit = credit
  10.  
  11.     # member functions
  12.     def balance(self) :
  13.         return self.Balance
  14.  
  15.     def deposit(self, amount) :  
  16.         self.Balance = amount
  17.    
  18.     def transfer(self, target, amount) :
  19.         if (self.Balance - amount < -self.LineOfCredit) :
  20.             # insufficient funds
  21.             return False  
  22.         else :
  23.             self.Balance -= amount
  24.             target.Balance += amount
  25.             return True
  26.  
  27.     def withdraw(self, amount) :
  28.         if (self.Balance - amount < -self.LineOfCredit) :
  29.             # insufficient funds
  30.             return False  
  31.         else :
  32.             self.Balance -= amount
  33.             return True
  34.  
  35.  
  36.  
  37. # instantiate a class object
  38. acctInfoCustomer1 = BankAccount("King", 27427, 19231.10)
  39. # verify the account balance
  40.  
  41. # display account information
  42. acctInfoCustomer2 = BankAccount("Hasan", 27428, 1953100.10)
  43. # verify the account balance
  44.  
  45.  
  46. acctInfoCustomer2.transfer(acctInfoCustomer1, 5999)
  47. acctInfoCustomer2.withdraw(2000)
  48. bal1 = acctInfoCustomer1.balance()
  49. bal2 = acctInfoCustomer2.balance()
  50. print (acctInfoCustomer1.Holder)
  51. print (acctInfoCustomer1.Number)
  52. print ("\nBalance: $%.2f" % bal1)
  53.  
  54. print ("\n")
  55.  
  56.  
  57. # display account information
  58. print (acctInfoCustomer2.Holder)
  59. print (acctInfoCustomer2.Number)
  60. print ("\nBalance: $%.2f" % bal2)
  61.  
  62. print ("\n")
  63. #19231.0
  64. #19532100.10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement