Time: 1 hour
Create a command line program that works as a simple hotel management system. It should process n
transactions. Each transaction can either:
- Create hotels
- Book a hotel within a specified date range
- Cancel bookings
The program should handle potential conflicts in booking dates that might occur from user input. When the program terminates, it should report all bookings for all hotels.
- Hotels and bookings should have auto-incremented IDs to identify them. Users don't need to input IDs manually.
- Booking IDs should not rely on specific hotels. They should be system-wide counting numbers.
- Assume:
- There is only one room per hotel.
- Dates are represented as numbers from 1 to 365.
- The first line contains an integer
n
(where1 ≤ n ≤ 100,000,000
), representing the number of commands. - The next
n
lines describe each transaction. The transaction can follow one of these formats:
create hotel <hotel-name>
book <hotel-id> <check-in-date> <check-out-date>
cancel <hotel-id> <booking-id>
- Report all hotels in the system with their bookings. (Any format or order is acceptable.)
7
create hotel A
book 1 5 10
create hotel B
book 2 1 10
book 1 12 18
book 2 20 25
cancel 2 4
Hotel: A
Booking Id 1: 5 -> 10
Booking Id 3: 12 -> 18
Hotel: B
Booking Id 2: 1 -> 10
Explanation:
Hotel A
is created first and automatically gets hotel ID1
.- A booking is made at hotel A from day
5
to10
(assigned booking ID1
). Hotel B
is created next (hotel ID2
).- A booking is made at hotel B from day
1
to10
(assigned booking ID2
). - Another booking is made at hotel A from day
12
to18
(assigned booking ID3
). - A booking is made at hotel B from day
20
to25
(assigned booking ID4
). - The command
cancel 2 4
removes booking ID4
from hotel B.
5
create hotel Test
book 1 1 5
book 1 10 14
book 1 2 4
book 1 16 20
Hotel: Test
Booking Id 1: 1 -> 5
Booking Id 2: 10 -> 14
Booking Id 3: 16 -> 20
Explanation:
Hotel Test
is created and gets hotel ID1
.- Booking from day
1
to5
is assigned booking ID1
. - Booking from day
10
to14
is assigned booking ID2
. - The booking from day
2
to4
conflicts with booking ID1
and is not created. - Booking from day
16
to20
is successfully created and assigned booking ID3
.
- This problem evaluates Object-Oriented programming skills and code readability.
- We want to see if you can understand the problem and create objects that reflect the required behavior.
- Focus on class design and interface functionality first. Work on implementation, input parsing, and result display later.
- Use meaningful names for classes, variables, and methods.
- Handle edge cases to improve your solution.
- If in doubt, ask for clarification.