-
Notifications
You must be signed in to change notification settings - Fork 0
/
Composite.py
26 lines (21 loc) · 901 Bytes
/
Composite.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
from Product import Product
class Composite(Product):
def __init__(self, name, code, man_cost, constituents, vat_rate=0.18):
super().__init__(name, code)
self.__man_cost = man_cost
self.vat_rate = vat_rate
self.__constituents = constituents
@property
def get_man_cost(self):
return self.__man_cost
@property
def get_constituents(self):
return self.__constituents
def get_price(self):
total = sum(x.get_product.get_price for x in self.__constituents)
total += self.get_man_cost
return total
def __str__(self):
constituents_info = " ".join(f"{elem}" for elem in self.get_constituents)
return f"- {self.get_name}\n- Code: {self.get_code}\
\n- Manufacturing Cost: {self.get_man_cost}\n- Constituents:{constituents_info}- Purchase Price: {self.get_price()}"