Which of the following is the correct way to represent a parking spot in a class diagram?
easy🧠 Conceptual Q12 of Q15
LLD - Design — Parking Lot System
Which of the following is the correct way to represent a parking spot in a class diagram?
Aclass Vehicle { int spotNumber; boolean isOccupied; }
Bclass Spot { int spotNumber; boolean isOccupied; }
Cclass Floor { int spotNumber; boolean isOccupied; }
Dclass ParkingLot { int spotNumber; boolean isOccupied; }
Step-by-Step Solution
Solution:
Step 1: Identify the class representing a parking spot
The Spot class should have attributes like spotNumber and isOccupied to represent a parking space.
Step 2: Check other classes for correctness
Vehicle represents cars, Floor represents a level, and ParkingLot represents the whole area, so they should not have spotNumber or isOccupied attributes.
Final Answer:
class Spot { int spotNumber; boolean isOccupied; } -> Option B
Quick Check:
Spot class holds spot info = A [OK]
Quick Trick:Spot class holds spot details like number and occupancy [OK]
Common Mistakes:
MISTAKES
Assigning spot attributes to Vehicle
Putting spotNumber in Floor or ParkingLot
Confusing class roles in diagram
Master "Design — Parking Lot System" in LLD
9 interactive learning modes - each teaches the same concept differently