15089 - Walter White's Parking Empire   

Description

Walter White has decided to expand his business. After realizing that running a car wash isn't enough, he opens a parking garage in Albuquerque to help launder his money. Unfortunately, Jesse who was supposed to build the parking management system, can do nothing but to print("Yo, Mr. White!"), so Walter has now hired you to complete the job.

Your task is to implement a parking management system using Object-Oriented Programming (OOP). The system must register parking spaces, assign vehicles to suitable spaces, calculate parking fees, and track the current parking status.

The system consists of three main components:

  • Vehicle: A parent class containing common vehicle properties and methods. Motorcycle, Car, and Truck inherit from this class, each defining its own parking requirements and hourly rate. Trucks also have an additional service fee.
  • ParkingSpot: Represents an individual parking space with a unique ID, size, and occupancy status.
  • ParkingGarage: Manages all parking spaces, handles vehicle arrivals and departures, and maintains parking records.

 

Parking Rules

The garage accepts three types of vehicles:

Vehicle
Minimum Spot Size    
Hourly Rate
Motorcycle    
1
$10
Car
2
$20
Truck
3
$30

Walter insists that trucks need "special handling", so an additional $50 service fee applies to every truck departure, regardless of parking duration.

Parking spaces have three sizes:  SMALL (1), MEDIUM (2), and LARGE (3).

The system must follow these rules:

  1. A vehicle can only occupy an empty space that meets its minimum size requirement.
  2. When parking, choose the smallest available space that fits the vehicle. If multiple spaces have the same size, choose the one registered first.
  3. A vehicle cannot park twice using the same license plate.
  4. If no suitable space is available, reject the parking request.
  5. When a vehicle leaves, calculate its parking fee, free its space, and update the garage records.
  6. The garage must display the status of every parking space in registration order.

 

Your Mission

Complete all TODO sections in the provided starter code.

Use inheritance and method overriding to implement the different vehicle types. The system must correctly process parking requests, vehicle departures, and status queries according to the rules above.

Do not modify the provided main program.

 

Starter Code

class Vehicle:
    def __init__(self, plate):
       self.plate = plate

    def required_size(self):
        pass

    def hourly_rate(self):
        pass

    def fee(self, hours):
        return self.hourly_rate() * hours


class Motorcycle(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError


class Car(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError


class Truck(Vehicle):
    def required_size(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def hourly_rate(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def fee(self, hours):
        # TODO: Implement this method.
        raise NotImplementedError


class ParkingSpot:
    def __init__(self, spot_id, size):
        # TODO: Implement this method.

        # You might want to store a vehicle here
        raise NotImplementedError

    def is_free(self):
        # TODO: Implement this method.
        raise NotImplementedError

    def can_fit(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def assign_vehicle(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def remove_vehicle(self):
        # TODO: Implement this method.
        raise NotImplementedError


class ParkingGarage:
    def __init__(self):
        self.spots = []
        self.parked = {}

    def add_spot(self, spot):
        # TODO: Implement this method.
        raise NotImplementedError

    def park_vehicle(self, vehicle):
        # TODO: Implement this method.
        raise NotImplementedError

    def release_vehicle(self, plate, hours):
        # TODO: Implement this method.
        raise NotImplementedError

    def status_lines(self):
        # TODO: Implement this method.
        raise NotImplementedError


def create_vehicle(vehicle_type, plate):
    # TODO: Implement this function.
    raise NotImplementedError


if __name__ == "__main__":
    garage = ParkingGarage()
    sizes = {"SMALL": 1, "MEDIUM": 2, "LARGE": 3}

    n = int(input())

    for _ in range(n):
        spot_id, size_name = input().split()
        garage.add_spot(ParkingSpot(spot_id, sizes[size_name]))

    q = int(input())

    for _ in range(q):
        parts = input().split()
        command = parts[0]

        if command == "PARK":
            vehicle_type = parts[1]
            plate = parts[2]
            vehicle = create_vehicle(vehicle_type, plate)
            spot_id = garage.park_vehicle(vehicle)

            if spot_id is None:
                print(f"REJECTED {plate}")
            else:
                print(f"PARKED {plate} {spot_id}")

        elif command == "LEAVE":
            plate = parts[1]
            hours = int(parts[2])
            fee = garage.release_vehicle(plate, hours)

            if fee is None:
                print(f"NOT_FOUND {plate}")
            else:
                print(f"FEE {plate} {fee}")

        elif command == "STATUS":
            for line in garage.status_lines():
                print(line)

Input

The first line contains an integer N, representing the number of parking spaces.

The next N lines each contain two values:

spot_id size

  • spot_id: The unique identifier of the parking space.

  • size: The size of the parking space (SMALL, MEDIUM, or LARGE).

The next line contains an integer Q, representing the number of commands.

The following Q lines each contain one of three commands:

  • PARK type plate: Park a vehicle with the specified type (MOTORCYCLE, CAR, or TRUCK) and license plate.

  • LEAVE plate hours: Remove the vehicle with the specified license plate after hours hours and calculate its parking fee.

  • STATUS: Display the current status of every parking space.

Guarantees: All parking spaces are initially empty. Parking space IDs are unique. Vehicle types and commands are valid. Parking durations are nonnegative integers.

Output

For each command, print the corresponding result:

  • PARKED plate spot_id: The vehicle was successfully parked in the assigned parking space.

  • REJECTED plate: The vehicle could not be parked because its license plate is already registered or no suitable space is available.

  • FEE plate amount: The vehicle successfully left the garage, and amount is its total parking fee.

  • NOT_FOUND plate: The specified vehicle is not currently parked.

  • For STATUS, print spot_id plate for each occupied space or spot_id EMPTY for each empty space, in the order the spaces were registered.

Sample Input  Download

Sample Output  Download




Discuss