Skip to content

Ansh2625/Parking-Lot-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parking Lot System - Low Level Design (LLD)

A LLD implementation of real world parking lot management system using OOPS, SOLID principles and Design patterns.

Problem Statement

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.

Project Structure

parkinglot package

  • 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 package

  • 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 package

  • 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.

gates package

  • EntranceGate.java: Handles vehicle entry, ticket generation, and parking spot allocation.
  • ExitGate.java: Manages vehicle exit, calculates parking fees, and initiates payment processing.

Main.java

  • Entry point of application. Contains the main method to initialise and run the parking lot system.

UML Diagrams

Use Case Diagram

Use Case

Class Diagram

Class

Design Patterns used

Factory Design Pattern

  • 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, VehicleFactory is used to create instances of different types of vehicles (Bike, Car, Van, Truck) based on parking requirement.
  • Advantage - Extensibility & Loose Coupling.

Strategy Design Pattern

  • It is used to define a group of interchangeable algorithms and choose one at runtime.
  • In this project, PaymentStrategy is used to support multiple payment methods like Cash, CreditCard, UPI. PaymentService uses the chosen one at runtime.
  • Advantage - Flexible & Interchangeable logic.

Singleton Design Pattern

  • It ensures that only one instance of the class is created in the entire application. Must handle Multithreading case.
  • In this project, PaymentService & ParkingLot is implemented as Singleton class to maintain a single instance of it across the system.
  • Advantage - Shared instance, Global access.

How to Run

  1. Prerequisites:
  • Java 17 or later installed.
  • VS Code (recommended) or any Java-supported IDE.
  1. Clone the Repository:
git clone https://github.com/Ansh2625/Parking-Lot-System.git 
cd Parking-Lot-System
  1. Import the Project:
  • Open VS Code.
  • Select File > Open and choose the project's root folder (Parking-Lot-System).
  1. Build the Project:
  • Open Main.java file inside src.
  • Click the Run button on top, or right-click and choose Run java.
  1. Run the Application:
  • Right-click on Main.java.
  • Alternatively, use the terminal:
javac -d bin src/Main.java 
java -cp bin Main
  1. Interact with the System:
  • The system simulates parking operations.
  • Check console logs for actions like ticket generation, parking spot allocation, and payments.

Test Run

Features

  • 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.

Future Improvements

  • Add new Vehicle Types: Create a new class extending Vehicle.java.
  • Add new Payment Methods: Implement the PaymentStrategy.java interface.
  • Duration Calculation: Use a Map<ParkingSpot,Ticket> to store tickets and calculate the duration automatically at exit gate instead of asking the user.

License

This project is open-source and available under the MIT License.

Author

Developed by Ansh Sharma. Contact, anshsharma2625@gmail.com.

About

A console-based Parking Lot Management System using OOPS, SOLID principles, and Design Patterns.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages