diff --git a/battery.py b/battery.py new file mode 100644 index 000000000..975454a54 --- /dev/null +++ b/battery.py @@ -0,0 +1,14 @@ +from serviceable import Serviceable + +class Battery(Serviceable): + def __init__(self, last_service_date, current_date): + self.last_service_date = last_service_date + self.current_date = current_date + +class SpindlerBattery(Battery): + def needs_service(self) -> bool: + return (self.current_date - self.last_service_date).days >= 730 # 2 years + +class NubbinBattery(Battery): + def needs_service(self) -> bool: + return (self.current_date - self.last_service_date).days >= 1460 # 4 years diff --git a/car.py b/car.py index f7b980a1b..0d405a1a7 100644 --- a/car.py +++ b/car.py @@ -1,10 +1,11 @@ -from abc import ABC, abstractmethod +from serviceable import Serviceable +from engine import Engine +from battery import Battery +class Car(Serviceable): + def __init__(self, engine: Engine, battery: Battery): + self.engine = engine + self.battery = battery -class Car(ABC): - def __init__(self, last_service_date): - self.last_service_date = last_service_date - - @abstractmethod - def needs_service(self): - pass + def needs_service(self) -> bool: + return self.engine.needs_service() or self.battery.needs_service() diff --git a/engine/capulet_engine.py b/engine/capulet_engine.py deleted file mode 100644 index 69a2f3319..000000000 --- a/engine/capulet_engine.py +++ /dev/null @@ -1,13 +0,0 @@ -from abc import ABC - -from car import Car - - -class CapuletEngine(Car, ABC): - 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): - return self.current_mileage - self.last_service_mileage > 30000 diff --git a/engine/car_factory.py b/engine/car_factory.py new file mode 100644 index 000000000..8eea2c7e5 --- /dev/null +++ b/engine/car_factory.py @@ -0,0 +1,13 @@ +from datetime import date +from car import Car +from engine import CapuletEngine, SternmanEngine, WilloughbyEngine +from battery import SpindlerBattery, NubbinBattery + +class CarFactory: + @staticmethod + def create_calliope(current_mileage, last_service_mileage): + engine = CapuletEngine(last_service_mileage, current_mileage) + battery = SpindlerBattery(date.today(), date.today()) + return Car(engine, battery) + + # Additional methods for other car models... diff --git a/engine/engine.py b/engine/engine.py new file mode 100644 index 000000000..d15c27e44 --- /dev/null +++ b/engine/engine.py @@ -0,0 +1,21 @@ +from serviceable import Serviceable + +class Engine(Serviceable): + def __init__(self, last_service_mileage, current_mileage): + self.last_service_mileage = last_service_mileage + self.current_mileage = current_mileage + +class CapuletEngine(Engine): + def needs_service(self) -> bool: + return self.current_mileage - self.last_service_mileage >= 30000 + +class SternmanEngine(Engine): + def __init__(self, warning_light_on): + self.warning_light_on = warning_light_on + + def needs_service(self) -> bool: + return self.warning_light_on + +class WilloughbyEngine(Engine): + def needs_service(self) -> bool: + return self.current_mileage - self.last_service_mileage >= 60000 diff --git a/engine/model/__init__.py b/engine/model/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/engine/model/calliope.py b/engine/model/calliope.py deleted file mode 100644 index 1dd3da56d..000000000 --- a/engine/model/calliope.py +++ /dev/null @@ -1,12 +0,0 @@ -from datetime import datetime - -from engine.capulet_engine import CapuletEngine - - -class Calliope(CapuletEngine): - def needs_service(self): - service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False diff --git a/engine/model/glissade.py b/engine/model/glissade.py deleted file mode 100644 index e1b16ad27..000000000 --- a/engine/model/glissade.py +++ /dev/null @@ -1,12 +0,0 @@ -from datetime import datetime - -from engine.willoughby_engine import WilloughbyEngine - - -class Glissade(WilloughbyEngine): - def needs_service(self): - service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 2) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False diff --git a/engine/model/palindrome.py b/engine/model/palindrome.py deleted file mode 100644 index 590864bc8..000000000 --- a/engine/model/palindrome.py +++ /dev/null @@ -1,12 +0,0 @@ -from datetime import datetime - -from engine.sternman_engine import SternmanEngine - - -class Palindrome(SternmanEngine): - def needs_service(self): - service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False diff --git a/engine/model/rorschach.py b/engine/model/rorschach.py deleted file mode 100644 index b9eedc91d..000000000 --- a/engine/model/rorschach.py +++ /dev/null @@ -1,12 +0,0 @@ -from datetime import datetime - -from engine.willoughby_engine import WilloughbyEngine - - -class Rorschach(WilloughbyEngine): - def needs_service(self): - service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False diff --git a/engine/model/thovex.py b/engine/model/thovex.py deleted file mode 100644 index eac5707f0..000000000 --- a/engine/model/thovex.py +++ /dev/null @@ -1,12 +0,0 @@ -from datetime import datetime - -from engine.capulet_engine import CapuletEngine - - -class Thovex(CapuletEngine): - def needs_service(self): - service_threshold_date = self.last_service_date.replace(year=self.last_service_date.year + 4) - if service_threshold_date < datetime.today().date() or self.engine_should_be_serviced(): - return True - else: - return False diff --git a/engine/sternman_engine.py b/engine/sternman_engine.py deleted file mode 100644 index 72d8b5ab3..000000000 --- a/engine/sternman_engine.py +++ /dev/null @@ -1,15 +0,0 @@ -from abc import ABC - -from car import Car - - -class SternmanEngine(Car, ABC): - def __init__(self, last_service_date, warning_light_is_on): - super().__init__(last_service_date) - self.warning_light_is_on = warning_light_is_on - - def engine_should_be_serviced(self): - if self.warning_light_is_on: - return True - else: - return False diff --git a/engine/willoughby_engine.py b/engine/willoughby_engine.py deleted file mode 100644 index e5e0dc581..000000000 --- a/engine/willoughby_engine.py +++ /dev/null @@ -1,13 +0,0 @@ -from abc import ABC - -from car import Car - - -class WilloughbyEngine(Car, ABC): - 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): - return self.current_mileage - self.last_service_mileage > 60000 diff --git a/serviceable.py b/serviceable.py new file mode 100644 index 000000000..8e1a2add1 --- /dev/null +++ b/serviceable.py @@ -0,0 +1,3 @@ +class Serviceable: + def needs_service(self) -> bool: + raise NotImplementedError("Subclasses must implement this method")