-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS10L70_project11.py
71 lines (39 loc) · 2.31 KB
/
S10L70_project11.py
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
69
70
71
### Creating a BANK
## We will create 2 accounts, a current account and a savings account
# So we'll create an account parent class since both of them will have similar behaviour, deposit, withdraw money and print some statements
# Current account will have as limit 1000 EUR of negative for withdrawing and the saving accounts wont have any limit
# First the abstract class with the name/balance/min_balance, generally for every account
class Account:
# the constructor
def __init__(self, name, balance,min_balance):
self.name = name
self.balance = balance
self.min_balance = min_balance
# Method for doing deposit of the money into the accounts
def deposit(self, amount):
self.balance += amount # it's the same as writting self.balance = self.balance + amount
# Method for withdraw money
def withdraw(self,amount):
if self.balance - amount >= self.min_balance:
self.balance -= amount # it's the same as writting self.balance = self.balance + amount
else:
print("Sorry not enough funds")
#Method for print statement of the account
def statement(self):
print("Account Balance: {} Euros".format(self.balance))
## Now we have to create the class for current account inheriting from Account
class Current(Account):
#The constructor, the parameters needed to create a current account
def __init__(self, name, balance):
super().__init__(name, balance, min_balance = -1000) ## We'll pass here the maximum negative amount for the current account
# The class for showing the oject with some nice format
def __str__(self):
return("{}'s Current Account -> Balance {} Euros".format(self.name, self.balance))
## Now we have to create the class for savings account inheriting from Account
class Sabings(Account):
#The constructor, the parameters needed to create a current account
def __init__(self, name, balance):
super().__init__(name, balance, min_balance = 0) ## We'll pass here the maximum negative as 0 because it's a savings account
# The class for showing the oject with some nice format
def __str__(self):
return("{}'s Savings Account -> Balance {} Euros".format(self.name, self.balance))