FR:
NFR:
enum size {Compact, Large}
class Vehicle {
string regd
Size size
Spot spot
DateTime allotedAt
}
class SpotStatus {
Size size
int filled
int capacity
Object lock
}
class Lot {
private Map<Size, SpotStatus> spots
private Deque<Vehicle> waitingList;
private FareCalculator fareCalculator;
private int WLLimit;
void setFareCalculator(FareCalculator fareCalculator) {
this.fareCalculator= fareCalculator;
}
private boolean assignSpot(Vehicle vehicle) {
SpotStatus spotStatus = getSpotStatus(vehicle.size)
synchronized(spotStatus.lock) {
if (spotStatus.capacity - spotStatus.filled > 0) {
vehicle.allottedAt = java.time.LocalDateTime.now()
spotStatus.filled++
return true;
}
else return false;
}
}
public void assignSpotForArrivingVehicle(Vehicle vehicle) {
if (!assignSpot(vehicle)) {
if (waitingList.size() > WLLimit) waitingList.offer(vehicle);
else throw new WaitingListFullException();
}
}
// Below function runs in intervals like cron
public boolean assignSpotForWLVehice() {
Vehicle vehicle = q.peek();
if (assignSpot(vehicle)) waitingList.poll();
}
private SpotStatus getSpotStatus (Size size) {
spots.get(size);
}
public int calculateFare(Vehicle vehicle) {
return this.fareCalculator.calculateFare(java.time.LocalDateTime.now() - vehicle.allotedAt);
}
}
interface FareCalculator {
public int calculateFare()
}
class CompactFareCalculator implements FareCalculator {
public int calculateFare(int minutes) {
return 100 * minutes;
}
}
class LargeFareCalculator implements FareCalculator {
public int calculateFare(int minutes) {
return 200 * minutes;
}
}
Determine how these objects will interact with each other to fulfill the use cases...
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...
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
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.
public class Car { ... } // ExampleCheck 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...