Vehicle: Represents a vehicle entering or leaving the parking lot.
Parking Spot: Base class for different types of spots
Parking Lot: Contains parking lots.
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
class Vehicle {
String licensePlate;
String size;
LocalDateTime parkedTime;
double calculateFee(double dailyMax, double hourlyRate){
if(parkedTime == null){
return 0.0;
}
Duration sabun = Duration.between(parkedTime, LocalDateTime.now());
long hours = sabun.toHours();
if(hours >= 24){
return dailyMax;
}else{
return hours * hourlyRate;
}
}
}
class ParkingSpot{
String size;
boolean isAvailable = true;
Vehicle vehicle;
void assignVehicle(Vehicle vehicle){
this.vehicle = vehicle;
this.isAvailable = false;
}
void removeVehicle(){
this.vehicle = null;
this.isAvailable = true;
}
}
class ParkingLot{
//List<ParkingSpot> parkingSpots;
Map<Integer, List<ParkingSpot>> parkingSpots;
Map<String, Double> hourlyFee;
double dailyMax;
boolean checkAvailability(String size, int floorNumber){
for(Map.Entry<Integer, List<ParkingSpot>> parkingSpot:parkingSpots.entrySet()){
if(floorNumber == parkingSpot.getKey()){
List<ParkingSpot> spots = parkingSpot.getValue();
for(ParkingSpot spot:spots){
if(spot.isAvailable == spot.size.equals(size)){
return true;
}
}
}
}
return false;
}
ParkingSpot assignSpot(Vehicle vehicle, int floorNumber){
if(checkAvailability(vehicle.size, floorNumber)){
for(Map.Entry<Integer, List<ParkingSpot>> parkingSpot:parkingSpots.entrySet()){
if(floorNumber == parkingSpot.getKey()){
List<ParkingSpot> spots = parkingSpot.getValue();
for(ParkingSpot spot:spots){
spot.assignVehicle(vehicle);
spot.isAvailable = false;
return spot;
}
}
}
}
return null;
}
double calculateFee(Vehicle vehicle){
return vehicle.calculateFee(dailyMax,hourlyFee.get(vehicle.size));
}
}
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
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...
Critically examine your design for any flaws or areas for future improvement...