-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomposite.py
More file actions
179 lines (142 loc) · 5.14 KB
/
Copy pathcomposite.py
File metadata and controls
179 lines (142 loc) · 5.14 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class AbstractProduct:
name:str = None
price:float = None
def __init__(self, name, price):
self.name = name
self.price = price
def getName(self):
return self.name
def setName(self, name):
self.name = name
def getPrice(self):
return self.price
def setPrice(self, price):
self.price = price
class SimpleProduct(AbstractProduct):
brand:str = None
def __init__(self, name, price, brand):
super().__init__(name, price)
self.brand = brand
def getBrand(self):
return self.brand
def setBrand(self, brand):
self.brand = brand
class CompositeProduct(AbstractProduct):
products = []
def __init__(self, name):
super().__init__(name, 0)
def getPrice(self):
price = 0
for i in self.products:
price = price + i.getPrice()
return price
def setPrice(self):
pass
def addProduct(self, product:AbstractProduct):
self.products.append(product)
def removeProduct(self, product:AbstractProduct):
self.products.remove(product)
class SaleOrder:
orderID:float = None
customer:str = None
products:AbstractProduct = []
def __init__(self, orderID, customer):
self.orderId = orderID
self.customer = customer
def getPrice(self):
price:float = None
for i in self.products:
price = price + i.getPrice()
return price
def addProduct(self, product:AbstractProduct):
self.products.append(product)
def printOrder(self):
total:float = 0
print("\\\n=============================================")
print("\nOrden: ", self.orderId)
print("\nCliente: ", self.customer)
print("\nProductos:\n");
for i in self.products:
print(i.getName())
print(i.getPrice())
total = total+i.getPrice()
print("Total: ", total)
def getOrderId(self):
return self.orderId
def setOrderId(self, orderId:float):
self.orderId = orderId
def getCustomer(self):
return self.customer
def setCustomer(self, customer:str):
self.customer = customer
def getProducts(self):
return self.products
def setProducts(self, product:AbstractProduct):
self.products = product
def main():
ram4gb = SimpleProduct("Memoria RAM 4GB", 750, "KingStone");
ram8gb = SimpleProduct("Memoria RAM 8GB", 1000, "KingStone");
disk500gb = SimpleProduct("HDD 500GB", 1500, "ACME");
disk1tb = SimpleProduct("HDD 1TB", 2000, "ACME");
cpuAMD = SimpleProduct("Procesador AMD phenon", 4000, "AMD");
cpuIntel = SimpleProduct("Procesador Intel i7", 4500, "Intel");
smallCabinete = SimpleProduct("Gabinete Pequeño", 2000, "ExCom");
bigCabinete = SimpleProduct("Gabinete Grande", 2200, "ExCom");
monitor20inch = SimpleProduct("Monitor 20'", 1500, "HP");
monitor30inch = SimpleProduct("Monitor 30'", 2000, "HP");
simpleMouse = SimpleProduct("Mouse Simple", 150, "Genius");
gammerMouse = SimpleProduct("Mouse Gammer", 750, "Alien");
'''
simpleProductorder = SaleOrder(1, "Jose Truco")
simpleProductorder.addProduct(ram4gb)
simpleProductorder.addProduct(ram8gb)
simpleProductorder.addProduct(monitor30inch)
simpleProductorder.printOrder()
'''
#PC Gammer: Memoria RAM 8GB, HDD 1TB, Procesador Intel i7
#Gabinete Grande, Monitor 30', Mouse Gammer.
gammerPC = CompositeProduct("PC Gammer")
gammerPC.addProduct(ram8gb)
gammerPC.addProduct(disk1tb)
gammerPC.addProduct(cpuIntel)
gammerPC.addProduct(bigCabinete)
gammerPC.addProduct(monitor30inch)
gammerPC.addProduct(gammerMouse)
#PC Escritorio: Memoria RAM 4GB, HDD 500GB, Procesador AMD Phenon
#Gabinete Pequeño, Monitor 20', Mouse Simple.
homePC = CompositeProduct("PC Escritorio")
homePC.addProduct(ram4gb)
homePC.addProduct(disk500gb)
homePC.addProduct(cpuAMD)
homePC.addProduct(smallCabinete)
homePC.addProduct(monitor20inch)
homePC.addProduct(simpleMouse)
def orderSimpleProducts():
simpleProductOrder = SaleOrder(random.nextInt(), "Jerman Espíndola")
simpleProductOrder.addProduct(ram4gb)
simpleProductOrder.addProduct(disk1tb)
simpleProductOrder.addProduct(simpleMouse)
simpleProductOrder.printOrder()
def orderGammerPC():
gammerOrder = SaleOrder(1, "Matías Villega")
gammerOrder.addProduct(gammerPC)
gammerOrder.printOrder()
def orderHomePC():
homeOrder = SaleOrder(2, "Andrés Sanchez")
homeOrder.addProduct(homePC)
homeOrder.printOrder()
def orderCombo():
comboOrder = SaleOrder(3, "Paquete 2x1 en PC")
comboOrder.addProduct(pc2x1)
comboOrder.printOrder()
def orderBig():
customOrder = SaleOrder(4, "Andrés Espíndola")
customOrder.addProduct(homePC)
customOrder.addProduct(ram8gb)
customOrder.addProduct(ram4gb)
customOrder.addProduct(monitor30inch)
customOrder.addProduct(gammerMouse)
customOrder.printOrder()
orderBig()
if __name__ == '__main__':
main()