Skip to content

Commit d2b9b64

Browse files
Add automated coffee import by harvest season
Implemented a system to automatically determine coffee imports based on the harvest seasons: - Columbia (April to July) - Sumatra (August to November) - South Africa (January, February, December) - No imports in March due to no global harvest season. Utilized abstraction and polymorphism to select the appropriate import service based on the month input.
1 parent a7b8397 commit d2b9b64

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#Region Abstraction Example
3+
# Coffee beans are imported based on harvest seasons:
4+
# - Columbia (Apr-Jul: months 4-7)
5+
# - Sumatra (Aug-Nov: months 8-11)
6+
# - South Africa (Jan, Feb, Dec: months 1, 2, 12)
7+
# - No import in March (month 3)
8+
9+
from abc import ABC, abstractmethod
10+
11+
class BaseService(ABC):
12+
@abstractmethod
13+
def ship_from(self) -> str: pass
14+
15+
16+
class SumatraService(BaseService):
17+
def ship_from(self) -> str:
18+
return 'importing coffee from Sumatra'
19+
20+
class ColumbiaService(BaseService):
21+
def ship_from(self) -> str:
22+
return 'importing coffee from Columbia'
23+
24+
class SouthAfricaService(BaseService):
25+
def ship_from(self) -> str:
26+
return 'importing coffee from SouthAfrica'
27+
28+
class NoShipment(BaseService):
29+
def ship_from(self) -> str:
30+
return 'No shipment this month'
31+
32+
class Shipment:
33+
@staticmethod
34+
def shipment_method(month: int) -> BaseService:
35+
if 4 <= month <= 7:
36+
return ColumbiaService()
37+
elif 8 < month <= 11:
38+
return SumatraService()
39+
elif month in [1, 2, 12]:
40+
return SouthAfricaService()
41+
elif month == 3:
42+
return NoShipment()
43+
else:
44+
raise ValueError('Month must be between 1 and 12.')
45+
46+
def main():
47+
try:
48+
month = int(input('Enter the import month (1-12): '))
49+
service = Shipment.shipment_method(month)
50+
print(service.ship_from())
51+
except ValueError as e:
52+
print(f'Error: {e}')
53+
54+
main()

0 commit comments

Comments
 (0)