-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_7.py
117 lines (95 loc) · 3 KB
/
task_7.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
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
"""
Module for the UML of logistic system.
"""
import random
class Location:
"""
Class for location: city and post office.
"""
def __init__(self, city, postoffice):
self.city = city
self.postoffice = postoffice
def __repr__(self):
return f"Location({self.city}, {self.postoffice})"
class Item:
"""
Class for Item representation.
"""
def __init__(self, name, price):
self.name = name
self.price = price
def __str__(self):
return f"Item {self.name} costs {self.price}"
class Vehicle:
"""
Class for Vehicle representation.
"""
def __init__(self, vehicleNo, isAvailable=True):
self.vehicleNo = vehicleNo
self.isAvailable = isAvailable
class Order:
"""
Class for Order representation.
"""
def __init__(self, user_name, city, postoffice, items):
self.orderld = random.choice(range(100000000, 1000000000))
self.user_name = user_name
self.location = Location(city, postoffice)
self.items = items
self.vehicle = None
print(f"Your order number is {self.orderld}.")
def __str__(self):
return f"Order {self.orderld} for {self.user_name} to " + \
", ".join([self.location.city, str(self.location.postoffice)])
def calculateAmount(self):
"""
Method for computing the total price.
"""
return sum([item.price for item in self.items])
def assignVehicle(self, vehicle):
"""
Method for vehicle assignment.
"""
self.vehicle = vehicle
class LogisticSystem:
"""
Main class for Logistic System representation.
"""
def __init__(self, vehicles):
self.vehicles = vehicles
self.orders = []
def placeOrder(self, order):
"""
(Order) -> (None)
Method for placing an order if there is
any available vehicle.
"""
for vehicle in self.vehicles:
if vehicle.isAvailable:
self.orders.append(order)
order.assignVehicle(vehicle)
vehicle.isAvailable = False
break
check_lst = [veh for veh in self.vehicles if veh.isAvailable]
if not check_lst:
print("There is no available vehicle to deliver an order.")
def trackOrder(self, orderld):
"""
(int) -> (str)
Based on the previous order information,
returns either order delivery description or
a warning that the order does not exist.
"""
i = 0
while i < len(self.orders):
if self.orders[i].orderld == orderld:
break
i += 1
if i < len(self.orders):
our_ord = self.orders[i]
ult_price = our_ord.calculateAmount()
return f"Your order #{our_ord.orderld} is sent" + \
f" to {our_ord.location.city}" + \
f" Total price: {ult_price} UAH."
else:
return "No such order."