Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the role of the ParkingLot class in a parking system?
The ParkingLot class manages the entire parking area. It keeps track of floors, available spots, and overall capacity.
Click to reveal answer
beginner
What does the Floor class represent in a parking system?
The Floor class represents a single level within the ParkingLot. It contains multiple parking spots and manages their availability.
Click to reveal answer
beginner
What is the purpose of the Spot class in the parking system?
The Spot class represents an individual parking space. It can be assigned to a Vehicle and tracks if it is occupied or free.
Click to reveal answer
beginner
How does the Vehicle class fit into the parking system design?
The Vehicle class represents a car or other vehicle that needs parking. It holds details like vehicle type and license number.
Click to reveal answer
intermediate
Why is it important to identify classes like ParkingLot, Floor, Spot, and Vehicle separately?
Separating these classes helps organize the system clearly. Each class has a focused responsibility, making the design easier to manage and scale.
Click to reveal answer
Which class is responsible for managing multiple floors in a parking system?
AParkingLot
BFloor
CSpot
DVehicle
✗ Incorrect
The ParkingLot class manages multiple floors, overseeing the entire parking structure.
What does a Spot class instance represent?
AA parking space
BThe entire parking lot
CA floor in the parking lot
DA vehicle parked
✗ Incorrect
Spot represents an individual parking space where vehicles can park.
Which class would store a vehicle's license number?
AParkingLot
BFloor
CSpot
DVehicle
✗ Incorrect
Vehicle class holds details about the vehicle, including license number.
If you want to check if a parking spot is free, which class should you query?
AParkingLot
BFloor
CSpot
DVehicle
✗ Incorrect
Spot class tracks whether it is occupied or free.
Which class acts as a container for multiple Spot objects?
AVehicle
BFloor
CParkingLot
DSpot
✗ Incorrect
Floor contains multiple Spot instances representing parking spaces on that level.
Describe the responsibilities of the ParkingLot, Floor, Spot, and Vehicle classes in a parking system.
Think about how a real parking garage is organized from big to small parts.
You got /4 concepts.
Explain why separating the parking system into these classes helps in system design.
Consider how dividing tasks among team members makes work easier.
You got /4 concepts.
Practice
(1/5)
1. Which class in a parking system is responsible for managing multiple floors?
easy
A. ParkingLot
B. Floor
C. Spot
D. Vehicle
Solution
Step 1: Understand the role of ParkingLot
The ParkingLot class represents the entire parking area and manages multiple floors within it.
Step 2: Compare with other classes
Floor manages spots on a single level, Spot represents a single parking space, and Vehicle represents the car or bike.
Final Answer:
ParkingLot -> Option A
Quick Check:
ParkingLot manages floors = C [OK]
Hint: ParkingLot holds floors; floors hold spots [OK]
Common Mistakes:
Confusing Floor as managing multiple floors
Thinking Spot manages floors
Assigning Vehicle to manage floors
2. Which of the following is the correct way to represent a parking spot in a class diagram?
easy
A. class Vehicle { int spotNumber; boolean isOccupied; }
B. class Spot { int spotNumber; boolean isOccupied; }
C. class Floor { int spotNumber; boolean isOccupied; }
D. class ParkingLot { int spotNumber; boolean isOccupied; }
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]
Hint: Spot class holds spot details like number and occupancy [OK]
Common Mistakes:
Assigning spot attributes to Vehicle
Putting spotNumber in Floor or ParkingLot
Confusing class roles in diagram
3. Given the following code snippet, what will be the output?
The spots list is declared but not initialized, so calling add on it will cause a runtime error.
Step 2: Validate other options
Returning boolean is optional, Spot class can be separate, and Floor should have spots list to manage spots.
Final Answer:
spots list is not initialized before adding -> Option C
Quick Check:
Uninitialized list causes error = A [OK]
Hint: Always initialize lists before use [OK]
Common Mistakes:
Ignoring list initialization
Thinking method return type matters here
Believing Spot must be nested class
5. You want to design a system where each Vehicle can only park in a Spot that matches its size (e.g., small, medium, large). Which class design change best supports this requirement?
hard
A. Add a size attribute to both Vehicle and Spot classes and check compatibility before parking
B. Add a size attribute only to Vehicle class and ignore Spot size
C. Add a size attribute only to Spot class and ignore Vehicle size
D. Remove size attributes and allow any Vehicle to park anywhere
Solution
Step 1: Understand size matching requirement
Both Vehicle and Spot need size attributes to compare and ensure compatibility.
Step 2: Evaluate options
Ignoring size in either class prevents proper matching; removing size ignores requirement.
Final Answer:
Add a size attribute to both Vehicle and Spot classes and check compatibility before parking -> Option A
Quick Check:
Size match needs attributes in both classes = B [OK]
Hint: Both Vehicle and Spot need size info to match [OK]