The parking lot system will be used to manage parking lots with different vehicle sizes, multiple Levels, and various parking spot sizes.
Features:
2. Keep track of available spots
3. support multiple floors
4. Fee calculation
5. Users.
ParkingLot
ParkingFloor
ParkingSpot
Vehicle
ParkingTicket
2.ParkingFloor and ParkingSpot:
3.ParkingSpot and vehicle:
4.ParkingTicket and Vehicle:
5. User and the parking lot system
subclasses: Motorcycle, Car, Bus will inherit from Vehicle
subclasses: Admin, attendant, and Activeuser will inherit from the user and interact with the system based on their role.
Factory pattern
Attributes: For each class, define the attributes (data) it will hold...
Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
from enum import Enum
import datetime
class VehicleType(Enum):
MOTORCYCLE = 1
CAR = 2
BUS = 3
class UserType(Enum):
ADMIN = 1
ATTENDANT = 2
ACTIVEUSER = 3
class Vehicle:
def init(self, v_type: VehicleType, licence_plate):
self.v_type = v_type
self.licence_plate = licence_plate
def get_type(self):
return self.v_type
class ParkingSpot:
def init(self, spot_ID, spot_vehicle_type: VehicleType, floor):
self.spot_ID = spot_ID
self.spot_vehicle_type = spot_vehicle_type
self.floor = floor
self.is_available = True
self.vehicle = None
def can_fit_vehicle(self, vehicle) -> bool:
v_type = vehicle.get_type()
if self.is_available and self.spot_vehicle_type == v_type:
return True
else:
print("vehicle do not fit in")
return False
def park_vehicle(self, vehicle) -> bool:
if self.can_fit_vehicle(vehicle):
self.is_available = False
return True
else:
print("can't park vehicle"
return false
def remove_vehicle(self):
self.is_available = True
class ParkingFloor:
def init(self, floor_ID, spots):
self.floor_ID = floor_ID
self.spots = spots
def park_vehicle(self, vehicle) -> bool:
for spot in self.spots:
if spot.can_fit_vehicle(vehicle):
return spot.park_vehicle(vehicle)
return False
def remove_vehicle(self, vehicle) -> bool:
for spot in self.spots:
if spot.vehicle.license_plate == vehicle.license_plate:
spot.remove_vehicle()
return True
print("Vehicle is not in this floor:" + self.floor_ID)
return False
class ParkingLot:
def init(self, floors, spots, rate=20):
self.floors = floors
self.spots = spots
self.id_counter = 0
self.rate = rate
def park_vehicle(self, vehicle):
for floor in floors:
if floor.park_vehicle(vehicle):
entry_time = datetime.datetime.now()
ticket= ParkingTicket(self.id_counter, vehicle.licence_plate, entry_time)
self.id_counter+=1
def remove_vehicle(self, vehicle, ticket):
for floor in floors:
if floor.remove_vehicle(vehicle):
exit_time = datetime.datetime.now()
return self.calculate_fee(ticket, exit_time)
def calculate_fee(ticket:ParkingTicket, exit_time):
parking_duration = ticket.entry_time - self.exist_time
return self.rate * parking_duration
class ParkingTicket:
def init(self, ticket_ID, vehicle, entry_time):
self.ticket_ID = ticket_ID
self.vehicle = vehicle
self.entry_time = entry_time
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
single responsibility
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Critically examine your design for any flaws or areas for future improvement...