AP CSA FRQ Guide
2005 FRQ 1: Hotel
Reserve an available hotel room or append a guest to a waiting list, then cancel a reservation and reassign its room to the first waiting guest when one exists.
Reservation Arrays and Waiting Lists22 minute targetarraysArrayListobjectsnullslegacy raw types
Skills Tested
What this FRQ is really practicing
arraysArrayListobjectsnullslegacy raw types
Review these topics before attempting the problem.
Starter Approach
How to begin with your own plan
- 1Part A: find an empty entry in rooms, create and store a reservation using that room index, and return the stored reservation.
- 2If all rooms are occupied, append the guest name to waitList and return null.
- 3Part B: use the canceled reservation room number and reassign that exact room to the first waiting guest, removing that guest from the list.
- 4If no guest is waiting, mark the canceled room empty and return null.
Attempt the problem before opening the solution.
Common Mistakes
Mistakes to watch for while writing
Creating a reservation without storing it in the rooms array.
Returning a room number that differs from the reservation array index.
Reassigning a different room or taking a guest from the end of the waiting list.
Self Check
Review questions before you submit
Constructs a reservation for an available room.
The room number in the reservation must match its index in rooms.
Appends the guest to the waiting list when full.
Return null only after no empty room has been found.
Uses the canceled reservation room number.
Reassign the newly vacated room rather than another available room.
Removes the first waiting guest when reassigning a room.
The supplied waiting list is a raw ArrayList, so its returned guest name needs a String cast.
Practice Links
