Created
January 15, 2023 20:45
-
-
Save albexl/033fa4afa3afbb9b95f2300f0ab3bdd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""First Solution""" | |
from enum import Enum | |
class Person: | |
"""Person visitor""" | |
def __init__(self, id: str, name: str) -> None: | |
self.id = id | |
self.name = name | |
def __str__(self) -> str: | |
return self.id | |
class VehicleType(Enum): | |
"""Enum class to represent a Vehicle Type""" | |
AUTO = 1 | |
TRUCK = 2 | |
BUS = 3 | |
class Vehicle: | |
"""Vehicle visitor""" | |
def __init__(self, license_plate: str, vehicle_type: VehicleType) -> None: | |
self.license_plate = license_plate | |
self.vehicle_type = vehicle_type | |
def __str__(self) -> str: | |
return self.license_plate | |
class ResearchCenter: | |
"""Controller class""" | |
def __init__(self): | |
self.allowed_persons = [] | |
self.allowed_vehicles = [] | |
def add_person_visitor(self, person: Person) -> None: | |
"""Adds a person visitor to the list of allowed persons. | |
Args: | |
person (Person): The person visitor to add. | |
""" | |
self.allowed_persons.append(person) | |
def add_vehicle_visitor(self, vehicle: Vehicle) -> None: | |
"""Adds a vehicle visitor to the list of allowed vehicles. | |
Args: | |
vehicle (Vehicle): The vehicle visitor to add. | |
""" | |
self.allowed_vehicles.append(vehicle) | |
def verify_person_access(self, person: Person) -> bool: | |
"""Verifies that a person is authorized to enter. | |
Args: | |
person (Person): The person to check for access. | |
Returns: | |
bool: True if the person has access, False otherwise. | |
""" | |
for registered_person in self.allowed_persons: | |
if registered_person.id == person.id: | |
return True | |
return False | |
def verify_vehicle_access(self, vehicle: Vehicle) -> bool: | |
"""Verifies that a vehicle is authorized to enter. | |
Args: | |
vehicle (Vehicle): The vehicle to check for access. | |
Returns: | |
bool: True if the vehicle has access, False otherwise. | |
""" | |
for registered_vehicle in self.allowed_vehicles: | |
if registered_vehicle.license_plate == vehicle.license_plate: | |
return True | |
return False | |
if __name__ == "__main__": | |
carlos = Person("11111111111", "Carlos") | |
truck = Vehicle("ABC123", VehicleType.TRUCK) | |
bus = Vehicle("XYZ789", VehicleType.BUS) | |
center = ResearchCenter() | |
center.add_person_visitor(carlos) | |
center.add_vehicle_visitor(truck) | |
print(center.verify_person_access(carlos)) | |
print(center.verify_vehicle_access(truck)) | |
print(center.verify_vehicle_access(bus)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment