A conference room booking system allows users to reserve rooms, check availability, and cancel bookings. This is a great example of Object-Oriented Programming (OOP), as it involves:
✅ Attributes: Room names, booking status, and reservation details.
✅ Methods: Booking a room, checking availability, canceling a reservation, and displaying booked rooms.
✅ Encapsulation: Ensuring only valid bookings and cancellations are processed.
By structuring the system as a class, we organize data and behavior efficiently, making it scalable and maintainable.
class ConferenceRoomBooking:
"""Class representing a conference room booking system."""
def __init__(self):
"""Initialize available rooms and their booking status."""
self.rooms = {
"Room A": None,
"Room B": None,
"Room C": None
}
def book_room(self, room_name, person_name):
"""Book a room if it's available."""
if room_name in self.rooms:
if self.rooms[room_name] is None:
self.rooms[room_name] = person_name
print(f"✅ {room_name} successfully booked for {person_name}.")
else:
print(f"❌ {room_name} is already booked by {self.rooms[room_name]}.")
else:
print("❌ Invalid room name.")
def cancel_booking(self, room_name, person_name):
"""Cancel a booking if the person matches the reservation."""
if room_name in self.rooms:
if self.rooms[room_name] == person_name:
self.rooms[room_name] = None
print(f"✅ Booking for {room_name} has been canceled by {person_name}.")
else:
print(f"❌ Cannot cancel. Either the room is not booked or booked by someone else.")
else:
print("❌ Invalid room name.")
def check_availability(self):
"""Check available rooms."""
available_rooms = [room for room, booked_by in self.rooms.items() if booked_by is None]
if available_rooms:
print("Available Rooms:", ", ".join(available_rooms))
else:
print("❌ No rooms available.")
def display_bookings(self):
"""Display all booked rooms."""
print("📅 Current Bookings:")
for room, booked_by in self.rooms.items():
if booked_by:
print(f"{room}: Booked by {booked_by}")
else:
print(f"{room}: Available")
# Creating a ConferenceRoomBooking object
booking_system = ConferenceRoomBooking()
# Booking rooms
booking_system.book_room("Room A", "Alice")
booking_system.book_room("Room B", "Bob")
booking_system.book_room("Room A", "Charlie") # Should fail
# Checking availability
booking_system.check_availability()
# Displaying bookings
booking_system.display_bookings()
# Canceling a booking
booking_system.cancel_booking("Room A", "Alice")
# Checking availability after cancellation
booking_system.check_availability()
✅ Room A successfully booked for Alice.
✅ Room B successfully booked for Bob.
❌ Room A is already booked by Alice.
Available Rooms: Room C
📅 Current Bookings:
Room A: Booked by Alice
Room B: Booked by Bob
Room C: Available
✅ Booking for Room A has been canceled by Alice.
Available Rooms: Room A, Room C
ConferenceRoomBooking
class
self.rooms
).book_room()
method
cancel_booking()
method
check_availability()
method
display_bookings()
method
Alice
and Bob
book Room A and B.Charlie
tries to book an already occupied room (fails).✅ Encapsulation: Prevents unauthorized booking/canceling.
✅ Code Reusability: Easily extend with features (e.g., time slots).
✅ Scalability: Expand to more rooms or user authentication.