forked from sirfaheem/ComputerScienceALevels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassBankAC.py
More file actions
68 lines (60 loc) · 2.02 KB
/
ClassBankAC.py
File metadata and controls
68 lines (60 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class BankAC():
def __init__(self, t="",acno=0, bal=0):
self.__title = t
self.__acNo = acno
self.__balance = bal
self.__creationDate = None
self.__initialDeposit = bal
self.__acType = ""
def output(self):
print("account No: ", self.__acNo)
print("Title: ", self.__title)
print("Balance: ", self.__balance)
print("Account Type:", self.__acType)
def getBalance(self):
return self.__balance
def setBalance(self, b):
self.__balance = b
def getDetails(self):
return self.__acNo, self.__title, self.__balance
def withdraw(self, amount=0):
if amount>self.__balance:
print("Limit Exceed!")
else:
self.__balance-=amount
def deposit(self, amount=0):
if amount>=0:
self.__balance+=amount
class Savings(BankAC): #inheritence
def __init__(self, t="",acno=0,
init=0, rate=2.5):
BankAC.__init__(self, t,acno, init)
BankAC.__acType = "Savings"
self.__iRate = rate
def output(self):
BankAC.output(self) #polymorphism
print("interest Rate: ", self.__iRate)
def calculateInterest(self):
newBal = BankAC.getBalance(self)*self.__iRate
newBal += BankAC.getBalance(self)
BankAC.setBalance(self,newBal)
class Current(BankAC):
def __init__(self, t="",acno=0, init=0, od=0):
BankAC.__init__(self, t,acno, init)
BankAC.__acType = "Current"
self.__ODLimit = od
def setODLimit(self, amount):
self.__ODLimit = amount
def getODLimit(self):
return self.__ODLimit
def output(self):
BankAC.output(self) #polymorphism
print("Overdraft Limit: ", self.__ODLimit)
ac1 = Savings("faheem", 2341, 2000, 3.5)
ac1.output()
ac1.deposit(1000)
ac1.calculateInterest()
ac1.output()
ac2 = Current("ahmed", 2231, 3000)
ac2.withdraw(50000)
ac2.output()