Problem definition
A parking lot is a designated area for parking vehicles and is a feature found in almost all popular venues such as shopping malls, sports stadiums, offices, etc.
In a parking lot, there are a different parking spots available for different types of vehicles. Each of these spots is charged according to the time the vehicle has been parked in the parking lot. The parking time is tracked with a parking ticket issued to the vehicle at the entrance of the parking lot. Once the vehicle is ready to exit, it can pay at the exit gate using a card, card or UPI payment method.
Requirements
- Parking Lot should have multiple floors
- Parking Lot should have multiple entry and exit gates
- It should support parking of multiple vehicles- two, four, heavy
- Ticket must be generated at entry gate
- Payment should be done at exit gate through different modes- cash, card, upi
- Payment can be done on hourly or minute basis.
- Parking Space must be allocated close to the entrance gate of vehicle
Objects Required
- Vehicle
- Parking Lot
- Floor
- Parking Space- two-wheeler, four-wheeler, heavy-vehicle
- Entry Gate
- Exit Gate
- GateManager
- Ticket
- Payment
- Payment Strategy
class Vehicle
{
int regNum;
VehicleType vType;
//define getter and setter in each class
}
public enum VehicleType
{
TWO, FOUR, HEAVY;
}
class ParkingSpace
{
int spaceId;
int floorId;
Vehicle vehicle;
int price;
boolean isEmpty;
public void parkVehicle(Vehicle v)
{
isEmpty= false;
vehicle= v;
}
public void removeVehicle()
{
vehicle= null;
isEmpty= True;
}
}
class TwoWheelerSpace extends ParkingSpace
{
int price= 10;
}
class FourWheelerSpace extends ParkingSpace
{
int price= 20;
}
class HeavyVehicleSpace extends ParkingSpace
{
int price= 40;
}
class Floor
{
int floorId;
boolean isEmpty;
List<ParkingSpace> pSpaces;
public void addParkingSpace(ParkingSpace p){}
public void removeParkingSpace(ParkingSpace p){}
}
class PakingSpaceFactory
{
ParkingSpace pSpace;
public ParkingSpace getParkingSpace(Vehicle v)
{
//return object of TwoWheelerSpace or FourWheeler based on VehicleType
}
}
class ParkingLot
{
List<Floor> floorList; //initialized in constructor
ParkingSpaceFactory pSpaceFact;
public void addFloor(Floor f, List<ParkingSpace> p){}
public void removeFloor(Floor f){}
public ParkingSpace findParkingSpace(EntryGate entry, Vehicle v)
{
//Parking space found on the basis of type of vehicle using ParkingSpace Factory class
//Parking space is found close to entry gate
}
}
class GateManager
{
List<EntryGate> entries;
List<ExitGate> exits;
public void addEntryGate(EntryGate entry){}
public void removeEntryGate(EntryGate entry){}
public void addExitGate(ExitGate exit){}
public void removeExitGate(ExitGate exit){}
}
class EntryGate
{
int gateid;
ParkingLot pLot;
public Vehicle getVehicle(Vehicle v){}
public ParkingSpace findSpace(){
//uses object of parkingLot to find Space
}
public void updateParkingSpace(ParkingSpace pSpace){}
public Ticket generateTicket(){}
}
class Ticket
{
int ticketId;
Date today;
Time entryTime;
Time exitTime;
Vehicle v;
ParkingSpace pSpace;
public void getExitTime(Time time){}
}
class PaymentInfo
{
int transactionId;
double amount;
Date date;
Ticket ticket;
PaymentType pType;
PaymentStrategy pStrategy;
}
public enum PaymentType
{
CASH, CARD, UPI;
}
class ExitGate
{
int gateId;
Ticket t;
public double calculatePrice(PaymentStrategy pStrategy)
{
return pStrategy* calculateCost();
}
public PaymentInfo generatePaymentInfo(PaymentType pType){}
public void freeParkingSpace(){}
}
class PaymentStrategy
{
public double calculateCost(){}
}
class HourlyPaymentStrategy extends PaymentStrategy
{
public double calculateCost(Ticket t)
{
double parkedTime=(Currenttime- t.entryTime); // convert to hours
return parkedTime * t.pSpace.price;
}
}
class MinutesPaymentStrategy extends PaymentStrategy
{
public double calculateCost(Ticket t)
{
double parkedTime=(Currenttime- t.entryTime); // convert to minutes
return parkedTime * t.pSpace.price;
}
}
Top comments (0)