──────────────────────────────────────

32. Festival Room Booking · Build a Festival Room Booker

Coordinate rooms and bookings so each request gets the first suitable room, and failed requests preserve availability.

Lesson files · lessons/composition/festival-booking-project

Before you start
- Use one class to hold an instance of another class.
- Override a method for a specialised room.
- Keep a record of whether an item has been taken.

By the end
- Assign each group to the first available room it fits and return a readable booking.
- Use the repeated-request checks to explain what changes after a booking and after a failed request.

Where you can use it
Assign room requests for one festival session in order and tell an organiser which groups still need a room.

Plan for a single time slot. Each Room keeps its capacity and whether it is booked. A Booking names the group and holds the assigned Room. RoomBooker owns the room list and asks each room whether it fits. It changes the first suitable room to booked and returns a Booking. If the whole list is unsuitable, the method returns None. Keeping the input and display outside book makes it possible to test the booking rules with objects alone.

Predict
Which room does a five-person group receive when both rooms fit?
- Hall.
- Studio.

Worked example (example.py)

def first_fit(people, room_sizes):
    for name, size in room_sizes:
        if people <= size:
            return name
    return None


rooms = [("Studio", 6), ("Hall", 20)]
print(first_fit(5, rooms))
print(first_fit(21, rooms))


Example result
Studio
None

Complete WorkshopRoom.usable_seats() so it reserves two seats for facilitators, with a floor of zero. Complete RoomBooker.book(group, people). Ask each room whether it fits. Mark the first room that fits as booked, then return a Booking for that room. Return None after the loop if no room fits. The first input line gives the request count. Each later line gives a group name, a comma and a positive number of people. Keep the starter’s output format.

Starter program (starter.py)

class Room:
    def __init__(self, name, capacity):
        self.name = name
        self.capacity = capacity
        self.booked = False

    def usable_seats(self):
        return self.capacity

    def fits(self, people):
        return not self.booked and people <= self.usable_seats()


class WorkshopRoom(Room):
    pass


class Booking:
    def __init__(self, room, group, people):
        self.room = room
        self.group = group
        self.people = people

    def __str__(self):
        return f"{self.group} booked {self.room.name} for {self.people} people."


class RoomBooker:
    def __init__(self, rooms):
        self.rooms = rooms

    def book(self, group, people):
        return None


booker = RoomBooker([Room("Studio", 6), WorkshopRoom("Lab", 12)])
for _ in range(int(input())):
    group, count = input().split(",")
    booking = booker.book(group, int(count))
    if booking is None:
        print(f"No room for {group}.")
    else:
        print(booking)


Starter input
3
Film Club,7
Art Club,6
Science Club,4

Hint
Check room.fits(people) before setting room.booked to True. Return Booking(room, group, people) only after that check succeeds.

Case 1. Try the sample
Input
3
Film Club,7
Art Club,6
Science Club,4
Expected output
Film Club booked Lab for 7 people.
Art Club booked Studio for 6 people.
No room for Science Club.

Case 2. First suitable room wins
Input
2
Art Club,5
Science Club,3
Expected output
Art Club booked Studio for 5 people.
Science Club booked Lab for 3 people.

Case 3. Failed request preserves both rooms
Input
3
Film Club,11
Art Club,6
Science Club,10
Expected output
No room for Film Club.
Art Club booked Studio for 6 people.
Science Club booked Lab for 10 people.

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Write a test that calls book twice with the same room list. Assert that only one request can book the same room.

Reflect
Which test shows that checking whether a group fits leaves each room unchanged?

Check your prediction
Studio. The loop returns as soon as it reaches a suitable room.
