Requirements

Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.





Define Core Objects

Based on the requirements and use cases, identify the main objects of the system...






Analyze Relationships

Determine how these objects will interact with each other to fulfill the use cases...






Establish Hierarchy

Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...






Design Patterns

Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...






Define Class Members (write code)

Attributes: For each class, define the attributes (data) it will hold...

Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.


enum VehicleSize { COMPACT, STANDARD, LARGE } enum SpotType { COMPACT, STANDARD, LARGE, HANDICAPPED } class Vehicle { private String vehiId; // vehicle number private VehicleSize vehiSize; private boolean isDisable; private LocalTime start; private Spot spot; public Vehicle(String id, VehicleSize size, boolean isDisable) { this.vehiId = id; this.vehiSize = size; this.isDisable = isDisable; } // getter and setter private String getId() { return vehiId; } private VehicleSize getSize() { return vehiSize; } private boolean getIsDisable() { return isDisable; } private LocalTime getStart() { return start; } private void setStart() { this.start = LocalTime.now(); } private Spot getSpot() { return spot; } private void setSpot(Spot spot) { this.spot = spot; } } class Spot { private int spotId; private SpotType spotType; private boolean isAvailable; private int floor; private int row; private int col; public Spot(int spotId, SpotType spotType, true, int floor, char section, int row, int col) { this.spotId = spotId; this.spotType = spotType; this.isAvailable = true; this.floor = floor; this.row = row; this.col = col; } // getter and setter private SpotType getType() { return spotType; } private SpotType getType() { return spotType; } // spot availability checking private boolean getAvailable() { return isAvailable; } private int getFloor() { return floor; } private int getRow() { return row; } private int getCol() { return col; } } class Floor { private int number; private int totalRows; private int totalCols; private List<Spot> allCompaSpots; private List<Spot> allStanSpots; private List<Spot> allLargeSpots; private List<Spot> allHandiSpots; private List<Spot> avaliableCompaSpots; private List<Spot> avaliableStanSpots; private List<Spot> avaliableLargeSpots; private List<Spot> avaliableHandiSpots; //private List<Vehicle> vehicles; public Floor(int number, int totalRows, int totalCols, List<Spot> spots, List<Spot> avaliableSpots, List<Vehicle> vehicles) { this.number = number; this.totalRows = totalRows; this.totalCols = totalCols; this.allCompaSpots = allCompaSpots; this.allStanSpots = allStanSpots; this.allLargeSpots = allLargeSpots; this.allHandiSpots = allHandiSpots; this.avaliableCompaSpots = avaliableCompaSpots; this.avaliableStanSpots = avaliableStanSpots; this.avaliableLargeSpots = avaliableLargeSpots; this.avaliableHandiSpots = avaliableHandiSpots; //this.vehicles = vehicles; } public boolean isFullCurrFloor() { return ((avaliableCompaSpots.size() == 0) && (avaliableStanSpots.size() == 0) && (avaliableLargeSpots.size() == 0) && (avaliableHandiSpots.size() == 0)); } public Spot removeAnAvaSpot(SpotType spotType) { if (spotType == SpotType.COMPACT) { return removeAnAvaCompaSpot(); } else if (spotType == SpotType.STANDARD) { return removeAnAvaStanSpot(); } else if (spotType == SpotType.LARGE) { return removeAnAvaLargeSpot(); } else { return removeAnAvaHandiSpot(); } } public Spot removeAnAvaCompaSpot() { if (avaliableCompaSpots.size() == 0) { return null; } Spot avaliableCompaSpot = avaliableCompaSpots.get(avaliableCompaSpots.size() - 1); avaliableCompaSpots.remove(avaliableCompaSpots.size() - 1); return avaliableCompaSpot; } public Spot removeAnAvaStanSpot() { if (avaliableStanSpots.size() == 0) { return null; } Spot avaliableStanSpot = avaliableStanSpots.get(avaliableStanSpots.size() - 1); avaliableStanSpots.remove(avaliableStanSpots.size() - 1); return avaliableStanSpot; } public Spot removeAnAvaLargeSpot() { if (avaliableLargeSpots.size() == 0) { return null; } Spot avaliableLargeSpot = avaliableLargeSpots.get(avaliableLargeSpots.size() - 1); avaliableLargeSpots.remove(avaliableLargeSpots.size() - 1); return avaliableLargeSpot; } public Spot removeAnAvaHandiSpot() { if (avaliableHandiSpots.size() == 0) { return null; } Spot avaliableHandiSpot = avaliableHandiSpots.get(avaliableHandiSpots.size() - 1); avaliableHandiSpots.remove(avaliableHandiSpots.size() - 1); return avaliableHandiSpot; } public void addAnAvaSpot(Spot spot) { if (spot.getType() == SpotType.COMPACT) { avaliableCompaSpots.add(spot); } else if (spot.getType() == SpotType.STANDARD) { avaliableStanSpots.add(spot); } else if (spot.getType() == SpotType.LARGE) { avaliableLargeSpots.add(spot); } else { avaliableHandiSpots.add(spot); } } // public List<Vehicle> getVehicles() { // return vehicles; // } } class ParkingSystem { private List<Floor> floors; private int totalSpots; private int availCompaCount; private int availStanCount; private int availLargeCount; private int availHandiCount; public ParkingSystem(List<Floor> floors, int totalSpots, int currSpots) { this.floors = floors; this.totalSpots = totalSpots; this.currSpots = currSpots; } public boolean isFull() { return ((availCompaCount == 0) && (availStanCount == 0) && (availLargeCount == 0) && (availHandiCount == 0)); } public boolean park(Vehicle vehicle) { Spot currSpot = findASpot(vehicle); if (currSpot == null) { return false; } else { vehicle.setStart(); vehicle.setSpot(currSpot); return true; } } public Spot findASpot(Vehicle vehicle) { VehicleSize currVehiSize = vehicle.vehiSize; for (Floor floor : floors) { if (vehicle.isDisable) { if (floor.avaliableHandiSpots.size() != 0) { return floor.removeAnAvaSpot(HANDICAPPED); } } if (currVehiSize == VehicleSize.COMPACT) { if (floor.avaliableCompaSpots.size() != 0) { return floor.removeAnAvaSpot(COMPACT); } else if (floor.avaliableCompaSpots.size() != 0) { return floor.removeAnAvaSpot(STANDARD); } else { return null; } } else if (currVehiSize == VehicleSize.STANDARD) { if (floor.avaliableStanSpots.size() != 0) { return floor.removeAnAvaSpot(STANDARD); } else if (floor.avaliableLargeSpots.size() != 0) { return floor.removeAnAvaSpot(LARGE); } else { return null; } } else { if (floor.avaliableLargeSpots.size() != 0) { return floor.removeAnAvaSpot(Large); } else { return null; } } } } public double leave(Vehicle vehicle) { double pay = calculatePrice(vehicle); Spot currSpot = vehicle.getSpot(); Floor floor = floors.get(currSpot.getFloor()); floor.addAnAvaSpot(currSpot); return pay; } public double calculatePrice(Vehicle vehicle) { int start = vehicle.getStart(); int end = LocalTime.now(); SpotType type = vehicle.getSpot().getType(); double price = 0.0; if (type == SpotType.COMPACT) { price = 2.0; } else if (type == SpotType.STANDARD) { price = 2.0; } else if (type == SpotType.LARGE) { price = 3.0; } else { price = 1.5; } return price * (end - start); } }





Adhere to SOLID Guidelines

Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...






Consider Scalability and Flexibility

Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...






Create/Explain your diagram(s)

Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...






Future improvements

Critically examine your design for any flaws or areas for future improvement...