This project is a Java implementation of a car parking system that can accommodate different types of vehicles and supports a configurable cost strategy.
- Initialization: Initialize the parking lot with a given number of floors and car spaces per floor for each vehicle type.
- Add Vehicle: Add vehicle details to the parking lot, including the vehicle type, registration number, and color.
- Remove Vehicle: Remove a vehicle from the parking lot based on the registration number.
- Check Availability: Check the availability of vehicle spaces on a specific floor for a given vehicle type.
- ParkingLot: Represents the parking lot and manages vehicle spaces.
- Vehicle: Represents a vehicle with attributes such as vehicle type, registration number, and color.
- Floor: Represents a floor in the parking lot with attributes like floor number and vehicle spaces.
- ParkingSpace: Represents a vehicle space with attributes such as space number, availability, and vehicle type.
- CostStrategy: Represents the cost strategy for parking, allowing for varying costs based on the vehicle type.
To use the car parking system, follow these steps:
- Initialization: Initialize the parking lot by providing the total number of floors and vehicle spaces per floor for each vehicle type.
- Add Vehicle: Add vehicles to the parking lot using the
addVehicle
method. - Remove Vehicle: Remove vehicles from the parking lot using the
removeVehicle
method. - Check Availability: Check the availability of vehicle spaces on a specific floor for a given vehicle type using the
checkAvailability
method.
public class Main {
public static void main(String[] args) {
// Initialize parking lot
ParkingLot parkingLot = new ParkingLot(5, 5); // 5 floors, 5 spaces per floor
// Add vehicles
Vehicle bus1 = new Vehicle("Bus001", "Yellow", VehicleType.Bus);
Vehicle car1 = new Vehicle("Car001", "White", VehicleType.Car);
Vehicle car2 = new Vehicle("Car002", "Green", VehicleType.Car);
Vehicle sports1 = new Vehicle("Sports001", "Yellow", VehicleType.Sports);
Vehicle sports2 = new Vehicle("Sports002", "Red", VehicleType.Sports);
Vehicle sports3 = new Vehicle("Sports003", "Blue", VehicleType.Sports);
// Remove vehicle by registration number
parkingLot.removeVehicle("CAR123");
// Check availability
System.out.println(parkingLot.addVehicle(1, car1));
System.out.println(parkingLot.addVehicle(1, car2));
System.out.println(parkingLot.addVehicle(2, bus1));
System.out.println(parkingLot.addVehicle(8, sports2));
System.out.println(parkingLot.addVehicle(3, sports1));
System.out.println(parkingLot.addVehicle(5, sports3));
}
}
Special thanks to you for visiting my project, feel free to personalize the message according to your preferences!