A LLD implementation of real world parking lot management system using OOPS, SOLID principles and Design patterns.
Design a Parking Lot System with following Requirements:
- Have Entry and Exit gate.
- Have multiple floors in the parking lot.
- Vehicles Allowed : Motorcycle, Cars, Trucks, Vans.
- Four types of parking spots based on Vehicle Type.
- Disallow vehicle entry if parking lot reaches full capacity.
- A vehicle can be parked only at the spot for its vehicle type.
- Generate parking tickets with duration tracking.
- Payment methods : Cash, Credit Card and UPI.
- Parking charges based on Hourly Rate.
ParkingLot.java: Manages floors, entry gates, exit gates, and parking spot booking. A singleton class.ParkingFloor.java: Manages parking spots and updates its availability.ParkingSpot.java: Abstract representation of a parking spot.BikeParkingSpot.java,CarParkingSpot.java,OtherParkingSpot.java: Specific implementations for parking spots.Ticket.java: Represents a parking ticket issued to a vehicle.
Vehicle.java: Abstract class for vehicles.BikeVehicle.java,CarVehicle.java,OtherVehicle.java: Specific implementations for vehicles.VehicleFactory.java: Factory class to create vehicle instances based on vehicle type.
Payment.java: Manages payment logic.PaymentStrategy.java: Strategy pattern for payment processing.PaymentService.java: Selects and execute the appropriate payment strategy. A singleton class.CashPayment.java,CreditCardPayment.java,UPIPayment.java: Specific implementations for payment methods.
EntranceGate.java: Handles vehicle entry, ticket generation, and parking spot allocation.ExitGate.java: Manages vehicle exit, calculates parking fees, and initiates payment processing.
- Entry point of application. Contains the main method to initialise and run the parking lot system.
- It provides a way to create objects without exposing the instantiation logic to the client. It promotes loose coupling by delegating the object creation to a specific class.
- In this project,
VehicleFactoryis used to create instances of different types of vehicles (Bike, Car, Van, Truck) based on parking requirement. - Advantage - Extensibility & Loose Coupling.
- It is used to define a group of interchangeable algorithms and choose one at runtime.
- In this project,
PaymentStrategyis used to support multiple payment methods like Cash, CreditCard, UPI. PaymentService uses the chosen one at runtime. - Advantage - Flexible & Interchangeable logic.
- It ensures that only one instance of the class is created in the entire application. Must handle Multithreading case.
- In this project,
PaymentService&ParkingLotis implemented as Singleton class to maintain a single instance of it across the system. - Advantage - Shared instance, Global access.
- Prerequisites:
- Java 17 or later installed.
- VS Code (recommended) or any Java-supported IDE.
- Clone the Repository:
git clone https://github.com/Ansh2625/Parking-Lot-System.git
cd Parking-Lot-System- Import the Project:
- Open VS Code.
- Select
File > Openand choose the project's root folder (Parking-Lot-System).
- Build the Project:
- Open
Main.javafile inside src. - Click the Run button on top, or right-click and choose Run java.
- Run the Application:
- Right-click on
Main.java. - Alternatively, use the terminal:
javac -d bin src/Main.java
java -cp bin Main- Interact with the System:
- The system simulates parking operations.
- Check console logs for actions like ticket generation, parking spot allocation, and payments.
- Input File: Testcase.txt
- Output File: Sample_Output.txt
- Multi-floor parking lot with entry and exit gates.
- Support different parking spot types (Bike, Car, Van and Truck).
- Dynamic Parking spot allocation.
- Ticket generation for parked vehicles.
- Payment processing via Cash, CrediCard, or UPI.
- Easily extendable and modular codebase.
- Add new Vehicle Types: Create a new class extending
Vehicle.java. - Add new Payment Methods: Implement the
PaymentStrategy.javainterface. - Duration Calculation: Use a
Map<ParkingSpot,Ticket>to store tickets and calculate the duration automatically at exit gate instead of asking the user.
This project is open-source and available under the MIT License.
Developed by Ansh Sharma. Contact, anshsharma2625@gmail.com.