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 Hotel class in a hotel booking system?
The Hotel class manages hotel details like name, location, and a list of rooms it contains. It acts as a container for rooms and provides methods to add or find rooms.
Click to reveal answer
beginner
What attributes are typically included in the Room class?
The Room class usually includes attributes like room number, type (single, double, suite), price, and availability status.
Click to reveal answer
intermediate
How does the Booking class relate to Hotel and Room classes?
The Booking class represents a reservation and links a customer to a specific Room in a Hotel for a date range. It manages booking details like check-in and check-out dates.
Click to reveal answer
intermediate
Why is it important to check room availability before creating a Booking?
Checking room availability prevents double-booking the same room for overlapping dates, ensuring a reliable and consistent booking system.
Click to reveal answer
advanced
What design principle helps keep Hotel, Room, and Booking classes organized and maintainable?
Single Responsibility Principle: each class should have one clear responsibility, making the system easier to understand and modify.
Click to reveal answer
Which class should store the price of a hotel room?
AHotel
BBooking
CRoom
DCustomer
✗ Incorrect
The Room class holds details specific to each room, including its price.
What does the Booking class primarily represent?
AA hotel location
BA reservation for a room
CA list of rooms
DA room's features
✗ Incorrect
Booking represents a reservation linking a customer to a room for specific dates.
Which method is essential in the Hotel class to support booking?
ACancelBooking()
BCalculateRevenue()
CAddRoom()
DCheckRoomAvailability()
✗ Incorrect
Checking room availability is crucial before making a booking.
Why should the Booking class include check-in and check-out dates?
ATo determine booking duration
BTo calculate room size
CTo assign room numbers
DTo store hotel location
✗ Incorrect
Check-in and check-out dates define the length of the reservation.
Which design principle suggests each class should have one responsibility?
ASingle Responsibility Principle
BOpen/Closed Principle
CLiskov Substitution Principle
DDependency Inversion Principle
✗ Incorrect
Single Responsibility Principle states that a class should have only one reason to change.
Explain how Hotel, Room, and Booking classes interact in a hotel booking system.
Think about who owns what and how bookings are made.
You got /4 concepts.
Describe the key attributes and methods you would include in the Room class.
Focus on what defines a room and how it can be managed.
You got /5 concepts.
Practice
(1/5)
1. Which class is primarily responsible for storing information about individual rooms in a hotel system?
easy
A. Room
B. Hotel
C. Booking
D. Guest
Solution
Step 1: Understand the role of each class
The Hotel class manages the overall hotel, Booking handles reservations, and Room stores details about each room.
Step 2: Identify which class holds room details
Since Room is designed to represent individual rooms, it stores room number, type, and availability.
Final Answer:
Room -> Option A
Quick Check:
Room class = stores room info [OK]
Hint: Room class holds room details, not Hotel or Booking [OK]
Common Mistakes:
Confusing Hotel with Room class
Thinking Booking stores room details
Assuming Guest class stores room info
2. Which of the following is the correct way to represent a Booking class constructor in Python that takes room, guest, and date as parameters?
easy
A. def __init__(self, room, guest, date):
B. def Booking(room, guest, date):
C. def __booking__(self, room, guest, date):
D. def init(self, room, guest, date):
Solution
Step 1: Recall Python constructor syntax
Python constructors use the special method __init__ with self as the first parameter.
Step 2: Match the correct method signature
def __init__(self, room, guest, date): correctly uses def __init__(self, room, guest, date): which is the standard constructor format.
Final Answer:
def __init__(self, room, guest, date): -> Option A
Quick Check:
Constructor = __init__ method [OK]
Hint: Python constructors always use __init__(self, ...) [OK]
Common Mistakes:
Using method name other than __init__
Omitting self parameter
Using class name as method name
3. Given the following code snippet, what will be the output?
class Room:
def __init__(self, number):
self.number = number
self.is_available = True
class Booking:
def __init__(self, room):
self.room = room
self.room.is_available = False
room101 = Room(101)
print(room101.is_available)
booking1 = Booking(room101)
print(room101.is_available)
medium
A. True\nTrue
B. False\nTrue
C. False\nFalse
D. True\nFalse
Solution
Step 1: Check initial availability of room101
When room101 is created, is_available is set to True, so first print outputs True.
Step 2: Booking changes room availability
Booking constructor sets room101.is_available to False, so second print outputs False.
Final Answer:
True\nFalse -> Option D
Quick Check:
Initial True, then set False by Booking [OK]
Hint: Booking sets room availability to False immediately [OK]
Common Mistakes:
Assuming availability stays True after booking
Confusing order of prints
Ignoring side effect on room object
4. Identify the error in the following Booking class code snippet:
class Room:
def __init__(self, number):
self.number = number
self.is_available = True
class Booking:
def __init__(self, room, guest):
self.room = room
self.guest = guest
def book(self):
if self.room.is_available:
self.room.is_available = False
print("Booking successful")
else:
print("Room not available")
room = Room(201)
booking = Booking(room)
booking.book()
medium
A. is_available should be a method, not attribute
B. Missing guest argument when creating Booking instance
C. book method should return a value
D. Room class is not defined
Solution
Step 1: Check Booking constructor parameters
Booking __init__ requires room and guest, but only room is passed when creating booking instance.
Step 2: Identify missing argument error
Omitting guest argument causes a TypeError at runtime.
Final Answer:
Missing guest argument when creating Booking instance -> Option B
Quick Check:
Constructor args mismatch = missing guest [OK]
Hint: Match all constructor parameters when creating objects [OK]
Common Mistakes:
Ignoring missing guest argument
Assuming book method must return value
Thinking is_available must be a method
5. You want to design a system where a Hotel manages multiple Rooms and allows Bookings only if rooms are available. Which design approach best supports scalability and maintainability?
hard
A. Make Booking class manage all Rooms and Guests directly, without Hotel involvement.
B. Store all booking data inside Room class only, without separate Booking class.
C. Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking.
D. Use a single class combining Hotel, Room, and Booking functionalities.
Solution
Step 1: Analyze class responsibilities
Hotel should manage Rooms, Booking should link Rooms and Guests, keeping clear separation.
Step 2: Evaluate design for scalability
Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking. cleanly separates concerns, allowing Hotel to check availability and Booking to handle reservations, supporting easy maintenance and scaling.
Final Answer:
Hotel manages Rooms; Booking references Room and Guest; Hotel checks availability -> Option C
Quick Check:
Separation of concerns = Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking. [OK]
Hint: Separate Hotel, Room, Booking roles for clean design [OK]