-
Notifications
You must be signed in to change notification settings - Fork 338
/
coupling-cohesion-after.py
70 lines (50 loc) · 2.02 KB
/
coupling-cohesion-after.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
import string
import random
class VehicleInfo:
def __init__(self, brand, electric, catalogue_price):
self.brand = brand
self.electric = electric
self.catalogue_price = catalogue_price
def compute_tax(self):
tax_percentage = 0.05
if self.electric:
tax_percentage = 0.02
return tax_percentage * self.catalogue_price
def print(self):
print(f"Brand: {self.brand}")
print(f"Payable tax: {self.compute_tax()}")
class Vehicle:
def __init__(self, id, license_plate, info):
self.id = id
self.license_plate = license_plate
self.info = info
def print(self):
print(f"Id: {self.id}")
print(f"License plate: {self.license_plate}")
self.info.print()
class VehicleRegistry:
def __init__(self):
self.vehicle_info = { }
self.add_vehicle_info("Tesla Model 3", True, 60000)
self.add_vehicle_info("Volkswagen ID3", True, 35000)
self.add_vehicle_info("BMW 5", False, 45000)
self.add_vehicle_info("Tesla Model Y", True, 75000)
def add_vehicle_info(self, brand, electric, catalogue_price):
self.vehicle_info[brand] = VehicleInfo(brand, electric, catalogue_price)
def generate_vehicle_id(self, length):
return ''.join(random.choices(string.ascii_uppercase, k=length))
def generate_vehicle_license(self, id):
return f"{id[:2]}-{''.join(random.choices(string.digits, k=2))}-{''.join(random.choices(string.ascii_uppercase, k=2))}"
def create_vehicle(self, brand):
id = self.generate_vehicle_id(12)
license_plate = self.generate_vehicle_license(id)
return Vehicle(id, license_plate, self.vehicle_info[brand])
class Application:
def register_vehicle(self, brand: string):
# create a registry instance
registry = VehicleRegistry()
vehicle = registry.create_vehicle(brand)
# print out the vehicle information
vehicle.print()
app = Application()
app.register_vehicle("Volkswagen ID3")