-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
62 lines (45 loc) · 1.4 KB
/
Copy pathcode.py
File metadata and controls
62 lines (45 loc) · 1.4 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
from abc import ABCMeta, abstractmethod
class Payment(metaclass=ABCMeta):
@abstractmethod
def do_pay(self):
pass
class Bank(Payment):
def __init__(self):
self.card = None
self.account = None
def __getAccount(self):
self.account = self.card # Supondo ser o número do cartão
return self.account
def __hasFunds(self):
print("Bank:: Checking if Account", self.__getAccount(), "has enough funds")
return True
def setCard(self, card):
self.card = card
def do_pay(self):
if self.__hasFunds():
print("Bank:: Paying the merchant")
return True
else:
print("Bank:: Sorry, not enough funds!")
class DebitCard(Payment):
def __init__(self):
self.bank = Bank()
def do_pay(self):
card = input("Proxy:: Punch in Card Number:")
self.bank.setCard(card)
return self.bank.do_pay()
class You:
def __init__(self):
print("You:: Lets buy the Denim shirt")
self.debitCard = DebitCard()
self.isPurchased = None
def make_payment(self):
self.isPurchased = self.debitCard.do_pay()
def __del__(self):
if self.isPurchased:
print("You:: Wow! Denim shirt is Mine :-)")
else:
print("You:: I should earn more :(")
if __name__ == "__main__":
you = You()
you.make_payment()