Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submission #153

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions battery.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 9 additions & 8 deletions car.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 0 additions & 13 deletions engine/capulet_engine.py

This file was deleted.

13 changes: 13 additions & 0 deletions engine/car_factory.py
Original file line number Diff line number Diff line change
@@ -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...
21 changes: 21 additions & 0 deletions engine/engine.py
Original file line number Diff line number Diff line change
@@ -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
Empty file removed engine/model/__init__.py
Empty file.
12 changes: 0 additions & 12 deletions engine/model/calliope.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/glissade.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/palindrome.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/rorschach.py

This file was deleted.

12 changes: 0 additions & 12 deletions engine/model/thovex.py

This file was deleted.

15 changes: 0 additions & 15 deletions engine/sternman_engine.py

This file was deleted.

13 changes: 0 additions & 13 deletions engine/willoughby_engine.py

This file was deleted.

3 changes: 3 additions & 0 deletions serviceable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Serviceable:
def needs_service(self) -> bool:
raise NotImplementedError("Subclasses must implement this method")