Skip to content

Commit

Permalink
add codebase for ParkingLot
Browse files Browse the repository at this point in the history
  • Loading branch information
msdeep14 committed Jan 16, 2023
1 parent 52142c2 commit 273a380
Show file tree
Hide file tree
Showing 69 changed files with 924 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LowLevelDesign/ParkingLot/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions LowLevelDesign/ParkingLot/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions LowLevelDesign/ParkingLot/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions LowLevelDesign/ParkingLot/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions LowLevelDesign/ParkingLot/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions LowLevelDesign/ParkingLot/ParkingLot.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
12 changes: 12 additions & 0 deletions LowLevelDesign/ParkingLot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Parking Lot Design
## Problem Statement
You own a parking lot of tech center where multiple company offices are co-located. You've design a parking space management system so as different companies cars/bikes can be parked in allocated slots. The employee of specific company should collect a ticket on entrance(if parking space is available) and pay the amount on exit from parking space.

## System Requirements
#### Vehicle Type
1. Two wheeler - bikes
2. Four wheeler - cars

#### Levels on parking space
The parking space can have multiple floors/levels

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
60 changes: 60 additions & 0 deletions LowLevelDesign/ParkingLot/src/ParkingLotApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import com.msdeepsingh.parkinglot.model.gate.EntranceGate;
import com.msdeepsingh.parkinglot.model.gate.ExitGate;
import com.msdeepsingh.parkinglot.model.parking.*;
import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket;
import com.msdeepsingh.parkinglot.model.vehicle.Vehicle;
import com.msdeepsingh.parkinglot.model.vehicle.VehicleType;
import com.msdeepsingh.parkinglot.service.impl.ParkingLotServiceImpl;
import com.msdeepsingh.parkinglot.service.ticket.impl.TicketServiceImpl;
import com.msdeepsingh.parkinglot.utility.ParkingUtility;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class ParkingLotApplication {
public static void main(String[] args) {
System.out.println("Welcome to Parking Lot!");

ParkingLot parkingLot = ParkingLot.getParkingLot();

ParkingLotServiceImpl parkingLotService = new ParkingLotServiceImpl(parkingLot);
TicketServiceImpl ticketService = new TicketServiceImpl();

//create parking spots
Map<Long, ParkingSpot> parkingSpotMap = new HashMap<>();
parkingSpotMap.put(1L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(1L, ParkingSpotType.FOUR_WHEELER), ParkingFloorNumber.GROUND));
parkingSpotMap.put(3L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(2L, ParkingSpotType.TWO_WHEELER), ParkingFloorNumber.GROUND));
parkingSpotMap.put(4L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(3L, ParkingSpotType.FOUR_WHEELER), ParkingFloorNumber.GROUND));
parkingSpotMap.put(5L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(4L, ParkingSpotType.TWO_WHEELER), ParkingFloorNumber.GROUND));

//create entry and entrance gate for ground floor
EntranceGate entranceGate = new EntranceGate(1L, ParkingFloorNumber.GROUND, true);
ExitGate exitGate = new ExitGate(2L, ParkingFloorNumber.GROUND, true);
Map<Long, EntranceGate> entranceGateMap = new HashMap<>();
entranceGateMap.put(1L, entranceGate);

Map<Long, ExitGate> exitGateMap = new HashMap<>();
exitGateMap.put(2L, exitGate);


//create Parking Floors
Map<ParkingFloorNumber, ParkingFloor> parkingFloorMap = new HashMap<>();
ParkingFloor groundParkingFloor = new ParkingFloor(ParkingFloorNumber.GROUND, parkingSpotMap, entranceGateMap, exitGateMap);
parkingFloorMap.put(ParkingFloorNumber.GROUND, groundParkingFloor);

//Initialize parking Lot with name identifier and parking floors information
parkingLot.setParkingLotId(UUID.randomUUID().toString());
parkingLot.setParkingLotName("Mandeep ka parking lot");
parkingLot.setParkingFloorMap(parkingFloorMap);

//create vehicle
Vehicle myHondaCar = new Vehicle("binaNumberWaliGadi", VehicleType.CAR);
Vehicle myHeroWaliMotorCycle = new Vehicle("127.0.0.1", VehicleType.BIKE);

//getParkingTicket
ParkingTicket carTicket = ticketService.getParkingTicket(myHondaCar, 1L);
System.out.println("Ticket generated successfully for vehicle: "+myHondaCar.getVehicleNo());
System.out.println("Ticket Details: "+carTicket);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.msdeepsingh.parkinglot.exception;

public class NonRetryableException extends RuntimeException {
private String message;

public NonRetryableException(String message) {
this.message = message;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.msdeepsingh.parkinglot.exception;

public class RetryableException extends RuntimeException {
private String message;

public RetryableException(String message) {
this.message = message;
}

@Override
public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msdeepsingh.parkinglot.model.gate;

import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber;

public class EntranceGate extends ParkingGate {

public EntranceGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) {
super(gateNo, floorNo, isOpen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.msdeepsingh.parkinglot.model.gate;

import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber;

public class ExitGate extends ParkingGate {

public ExitGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) {
super(gateNo, floorNo, isOpen);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.msdeepsingh.parkinglot.model.gate;

import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber;

public abstract class ParkingGate {
/**
* For unique representation of gates across the floor, the gate numbers are not repeated.
* */
private long gateNo;
private ParkingFloorNumber floorNo;
private boolean isOpen;

public ParkingGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) {
this.gateNo = gateNo;
this.floorNo = floorNo;
this.isOpen = isOpen;
}

public long getGateNo() {
return gateNo;
}

public void setGateNo(long gateNo) {
this.gateNo = gateNo;
}

public ParkingFloorNumber getFloorNo() {
return floorNo;
}

public void setFloorNo(ParkingFloorNumber floorNo) {
this.floorNo = floorNo;
}

public boolean isOpen() {
return isOpen;
}

public void setOpen(boolean open) {
isOpen = open;
}
}
Loading

0 comments on commit 273a380

Please sign in to comment.