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 main responsibility of the Elevator class in a building system?
The Elevator class manages the elevator's current state, including its current floor, direction, and the list of requests it needs to serve.
Click to reveal answer
beginner
How does the Floor class typically interact with the Elevator system?
The Floor class represents a building floor and can generate requests when a user wants to go up or down, signaling the Elevator system to respond.
Click to reveal answer
beginner
What information does a Request class usually contain in an elevator system?
A Request class contains details like the source floor, destination floor, and the direction of travel (up or down) to help the elevator decide its movement.
Click to reveal answer
intermediate
Why is it important for the Elevator class to maintain a queue of Requests?
Maintaining a queue helps the Elevator class efficiently plan stops and serve multiple requests in an organized manner, improving system responsiveness.
Click to reveal answer
intermediate
How can the Elevator system decide which request to serve next?
The system can use algorithms like 'nearest floor first' or 'direction-based scheduling' to pick the next request that minimizes travel time and wait time.
Click to reveal answer
Which class is responsible for generating a request when a user presses a button on a floor?
AFloor
BElevator
CRequest
DController
✗ Incorrect
The Floor class generates requests when users press buttons to go up or down.
What key data does a Request class NOT typically include?
ADestination floor
BUser's name
CSource floor
DDirection
✗ Incorrect
User's name is not usually part of the Request class; it focuses on floors and direction.
Why does the Elevator class keep track of its current floor?
ATo know where to stop next
BTo count passengers
CTo open doors automatically
DTo change the building's floor numbers
✗ Incorrect
Knowing the current floor helps the elevator decide which requests to serve next.
Which scheduling strategy helps an elevator serve requests efficiently?
ARandom floor selection
BServing requests in reverse order
CIgnoring requests
DNearest floor first
✗ Incorrect
Nearest floor first reduces travel time and wait time.
What does the Floor class represent in the elevator system?
AThe elevator's motor
BThe elevator's control panel
CA building level where users wait
DA request queue
✗ Incorrect
The Floor class models a building level where users can request elevators.
Explain the roles of Elevator, Floor, and Request classes in an elevator system.
Think about how a person calls and uses an elevator.
You got /3 concepts.
Describe how an elevator system decides which request to serve next and why this is important.
Consider how elevators avoid unnecessary travel.
You got /3 concepts.
Practice
(1/5)
1. What is the primary role of the Request class in an elevator system?
easy
A. To store the floor number and direction of a user's request
B. To move the elevator between floors
C. To open and close the elevator doors
D. To track the number of elevators in the building
Solution
Step 1: Understand the purpose of Request class
The Request class holds information about where a user wants to go and in which direction.
Step 2: Compare roles of other classes
Elevator moves and Floor represents building levels, but Request stores user input details.
Final Answer:
To store the floor number and direction of a user's request -> Option A
Quick Check:
Request = user floor and direction [OK]
Hint: Request class holds user floor and direction info [OK]
Common Mistakes:
Confusing Request with Elevator movement
Thinking Request controls doors
Mixing Request with Floor class responsibilities
2. Which of the following is the correct way to define a Request class constructor in Python to store floor and direction?
easy
A. def Request(floor, direction): self.floor = floor; self.direction = direction
B. def __init__(self, floor, direction): self.floor = floor; self.direction = direction
C. def __init__(floor, direction): self.floor = floor; self.direction = direction
D. def __init__(self): floor = None; direction = None
Solution
Step 1: Recall Python constructor syntax
Python constructors use def __init__(self, ...) and assign attributes with self.attribute = value.
Step 2: Check each option
def __init__(self, floor, direction): self.floor = floor; self.direction = direction correctly uses self and assigns floor and direction. Others miss self or parameters.
Final Answer:
def __init__(self, floor, direction): self.floor = floor; self.direction = direction -> Option B
Quick Check:
Constructor with self and attributes = def __init__(self, floor, direction): self.floor = floor; self.direction = direction [OK]
Hint: Python constructors need self parameter and attribute assignment [OK]
Common Mistakes:
Omitting self parameter
Using class name as constructor
Not assigning attributes to self
3. Given this Python snippet, what will be printed?
class Request:
def __init__(self, floor, direction):
self.floor = floor
self.direction = direction
r = Request(5, 'up')
print(r.floor, r.direction)
medium
A. Error: missing self
B. floor direction
C. 5 up
D. None None
Solution
Step 1: Understand object creation and attribute assignment
The Request object r is created with floor=5 and direction='up'. These are stored in attributes.
Step 2: Print attributes
Printing r.floor and r.direction outputs 5 and 'up' respectively.
Final Answer:
5 up -> Option C
Quick Check:
Attributes print as assigned = 5 up [OK]
Hint: Print object attributes to see stored values [OK]
Common Mistakes:
Expecting attribute names instead of values
Confusing class variables with instance variables
Assuming error without checking code carefully
4. Identify the error in this Elevator class snippet: