
Develop a CLI-based application.
Build an in-memory hostel guest-room allocation engine with interval-safe booking, deterministic best-fit room selection, waitlisting, cancellation, and clear separation between business logic and the CLI.
A college hostel has a limited number of rooms for students' parents and guardians. Rooms differ by capacity and facilities such as AC, ACCESSIBLE, and ATTACHED_BATHROOM.
A request should receive the best suitable room for the complete stay or be waitlisted when no room is available.
A room is eligible only when:
Choose among eligible rooms in this order:
A stay is represented as:
[startDay, endDay)
The interval is half-open.
For example:
[2,5) and [5,8)
do not conflict.
Requests can have one of these states:
CONFIRMED
WAITLISTED
CANCELLED
COMPLETED
WAITLISTED request has no room or booking assigned.CANCELLED request is terminal and must never be promoted.CONFIRMED or WAITLISTED.CANCELLED requests are not active.A submission sequence is assigned when requestRoom is called and never changes.
Booking IDs should be generated deterministically, for example:
B1, B2, ...
in confirmation order.
Students are fixed from:
u1 to u10
Facilities are:
AC
ACCESSIBLE
ATTACHED_BATHROOM
getRoomBookings, getStudentBookings, and getWaitlistedRequests must return deterministic ordering as specified below.
addRoom(roomId, capacity, facilities)
Return the room ID.
Rules:
requestRoom(
requestId,
studentId,
guestCount,
requiredFacilities,
startDay,
endDay
)
Return:
bookingIdroomId when confirmedValidation:
endDay > startDay.Reject the request if the student already has an overlapping active request, including an overlapping waitlisted request.
Then run the room allocation rules.
WAITLISTED with no room assignment.isRoomAvailable(roomId, startDay, endDay)
Return:
true / false
Return false when any active booking overlaps the requested half-open interval.
Adjacent stays do not overlap.
Example:
[2,5) and [5,8)
are compatible.
Invalid ranges and unknown rooms should return an error rather than false.
findBestRoom(guestCount, requiredFacilities, startDay, endDay)
Return:
null when no eligible room exists.Apply:
This method must not create a request or mutate booking state.
cancelRequest(requestId)
Return:
Rules:
processWaitlist()
Return the list of promoted requests with their:
Consider active waiting requests by:
For each request, re-run the same best-room allocation rules.
Leave incompatible requests waiting and continue to later requests.
Important: An older request requiring a four-person accessible room must not block a later request that can use an available two-person AC room.
getRequestStatus(requestId)
Return request details including:
Unknown request IDs return an error.
getRoomBookings(roomId)
Return the room's active bookings, sorted by:
startDayCancelled bookings are not active and must not block availability.
getStudentBookings(studentId)
Return all requests belonging to the student, including:
Order them by submission sequence.
Unknown students return an error.
getWaitlistedRequests()
Return active waitlisted requests ordered by:
Cancelled or confirmed requests must not appear.
Provide a numbered menu exposing all ten operations above, plus:
Exit
An equivalent REPL or command-based interface is acceptable if nothing is missing.
Print a clear result after every operation and return to the menu.
Use this scenario to validate:
Create:
R1: capacity 2, facilities [AC]
R2: capacity 2, facilities [AC, ATTACHED_BATHROOM]
R3: capacity 4, facilities [ACCESSIBLE, ATTACHED_BATHROOM]
R4: capacity 4, facilities [AC, ACCESSIBLE, ATTACHED_BATHROOM]
Submit a request for:
u1
2 guests
AC
[10,13)
R1, R2, and R4 satisfy the request.
The result must use:
R1
because it has the smallest sufficient capacity and fewer extra facilities than R2.
Submit another two-person AC request for:
[13,15)
It may use R1 because:
[10,13)
and
[13,15)
do not overlap.
When all compatible rooms are occupied during:
[11,12)
another two-person AC request should return:
WAITLISTED
with no room or booking ID.
Cancel a confirmed booking that frees a compatible room.
The waiting request should then be reconsidered and confirmed in the best available room.
The implementation must handle:
endDay <= startDay