-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.py
55 lines (42 loc) · 2.81 KB
/
Update.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
#Upgrade Spindler batteries:Modify the CapuletEngine class to update the engine_should_be_serviced method to require service after three years instead of two. You can achieve this by modifying the needs_service method to use years_threshold=3 instead of years_threshold=4 as follows:
class CapuletEngine(Car):
def __init__(self, last_service_date, current_mileage, last_service_mileage):
super().__init__(last_service_date)
self.current_mileage = current_mileage
self.last_service_mileage = last_service_mileage
def engine_should_be_serviced(self, mileage_threshold=30000):
return self.current_mileage - self.last_service_mileage > mileage_threshold
def needs_service(self, years_threshold=3, mileage_threshold=60000):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + years_threshold)
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(mileage_threshold)
#Add tire servicing criteria: Add a new method to the Car class
# called tire_should_be_serviced that takes an array of tire wear values and
# returns a boolean indicating whether the tires should be serviced based on the criteria for Carrigan and Octoprime tires. You can implement the method as follows:
class Car(ABC):
def __init__(self, last_service_date):
self.last_service_date = last_service_date
@abstractmethod
def engine_should_be_serviced(self):
pass
def needs_service(self, years_threshold=4, mileage_threshold=60000):
service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + years_threshold)
return service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(mileage_threshold)
def tire_should_be_serviced(self, tire_wear_values):
if isinstance(self, Carrigan):
return any(wear_value >= 0.9 for wear_value in tire_wear_values)
elif isinstance(self, Octoprime):
return sum(tire_wear_values) >= 3
else:
return False
#Then, add two new classes Carrigan and Octoprime that inherit from the Car class and override
# the tire_should_be_serviced method to implement the specific criteria for their respective tire
# types:
class Carrigan(Car):
def tire_should_be_serviced(self, tire_wear_values):
return any(wear_value >= 0.9 for wear_value in tire_wear_values)
class Octoprime(Car):
def tire_should_be_serviced(self, tire_wear_values):
return sum(tire_wear_values) >= 3
#With these modifications, you can use the needs_service and tire_should_be_serviced
# methods to determine when a car needs servicing and when its tires need to be serviced,
# respectively.