Hotel Booking System
Problem Statement
Section titled “Problem Statement”Design a hotel booking system that allows customers to search for available rooms, make reservations, manage bookings, and handle payments. The system should support multiple hotels, room types, booking cancellations, and pricing strategies.
Requirements
Section titled “Requirements”Functional Requirements
Section titled “Functional Requirements”- Search hotels by location, dates, and room type
- Check room availability for given dates
- Create, modify, and cancel bookings
- Support multiple room types (Single, Double, Suite)
- Handle payment processing
- Generate booking confirmations
- Manage customer profiles
- Support different pricing strategies (seasonal, weekend, holiday)
- Handle overbooking scenarios
- Send booking notifications
Non-Functional Requirements
Section titled “Non-Functional Requirements”- Handle concurrent bookings without double-booking
- High availability for search operations
- ACID properties for booking transactions
- Scalable to handle multiple hotels
- Fast search response time
Simplified Class Diagram
Section titled “Simplified Class Diagram”Simplified Overview
Section titled “Simplified Overview”Detailed Class Diagram
Section titled “Detailed Class Diagram”Key Design Patterns
Section titled “Key Design Patterns”- Strategy Pattern: Different pricing strategies
- Factory Pattern: Create bookings and rooms
- Observer Pattern: Notify users about booking status
- Singleton Pattern: BookingService as central coordinator
- Repository Pattern: Data access for hotels and bookings
Design Pattern Diagrams
Section titled “Design Pattern Diagrams”1. Strategy Pattern - Pricing Strategies
Section titled “1. Strategy Pattern - Pricing Strategies”2. Observer Pattern - Booking Notifications
Section titled “2. Observer Pattern - Booking Notifications”3. Factory Pattern - Room & Booking Creation
Section titled “3. Factory Pattern - Room & Booking Creation”4. Repository Pattern - Data Access Layer
Section titled “4. Repository Pattern - Data Access Layer”Code Snippets
Section titled “Code Snippets”Create Booking
Section titled “Create Booking”public class BookingService { public Booking createBooking(Guest guest, Room room, Date checkIn, Date checkOut) throws BookingException { synchronized(this) { // Check availability RoomInventory inventory = inventoryMap.get(room.getHotel().getHotelId()); if (!inventory.checkAvailability(room, checkIn, checkOut)) { throw new BookingException("Room not available for selected dates"); }
// Create booking Booking booking = new Booking(guest, room, checkIn, checkOut);
// Calculate price double totalAmount = pricingStrategy.calculatePrice(room, checkIn, checkOut); booking.setTotalAmount(totalAmount);
// Block room if (!inventory.blockRoom(room, checkIn, checkOut)) { throw new BookingException("Failed to block room"); }
// Save booking booking.setStatus(BookingStatus.PENDING); bookings.put(booking.getBookingId(), booking);
// Send notification notificationService.sendBookingConfirmation(booking);
return booking; } }}Check Room Availability
Section titled “Check Room Availability”public class RoomInventory { public boolean checkAvailability(Room room, Date checkIn, Date checkOut) { for (Booking booking : bookings) { if (!booking.getRoom().equals(room)) { continue; }
if (booking.getStatus() == BookingStatus.CANCELLED) { continue; }
// Check for overlap if (datesOverlap(booking.getCheckInDate(), booking.getCheckOutDate(), checkIn, checkOut)) { return false; } } return true; }
private boolean datesOverlap(Date start1, Date end1, Date start2, Date end2) { return !(end1.before(start2) || end2.before(start1)); }}Seasonal Pricing Strategy
Section titled “Seasonal Pricing Strategy”public class SeasonalPricing implements PricingStrategy { private Map<Season, Double> seasonRates;
@Override public double calculatePrice(Room room, Date checkIn, Date checkOut) { double basePrice = room.getPrice(); long nights = calculateNights(checkIn, checkOut);
double totalPrice = 0; Calendar cal = Calendar.getInstance(); cal.setTime(checkIn);
for (int i = 0; i < nights; i++) { Season season = getSeason(cal.getTime()); double multiplier = seasonRates.getOrDefault(season, 1.0); totalPrice += basePrice * multiplier; cal.add(Calendar.DAY_OF_MONTH, 1); }
return totalPrice; }
private Season getSeason(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int month = cal.get(Calendar.MONTH);
if (month >= 11 || month <= 1) return Season.WINTER; if (month >= 2 && month <= 4) return Season.SPRING; if (month >= 5 && month <= 7) return Season.SUMMER; return Season.FALL; }}Search Hotels
Section titled “Search Hotels”public class BookingService { public List<Hotel> searchHotels(SearchCriteria criteria) { List<Hotel> results = new ArrayList<>();
for (Hotel hotel : hotels.values()) { if (!matchesLocation(hotel, criteria.getLocation())) { continue; }
List<Room> availableRooms = hotel.getAvailableRooms( criteria.getCheckInDate(), criteria.getCheckOutDate(), criteria.getRoomType() );
if (!availableRooms.isEmpty()) { results.add(hotel); } }
return results; }}Extension Points
Section titled “Extension Points”- Add loyalty programs and rewards
- Implement dynamic pricing based on demand
- Add room upgrade options
- Support group bookings
- Implement waitlist for fully booked hotels
- Add review and rating system
- Support multi-room bookings
- Implement booking modifications with price adjustments
- Add integration with payment gateways
- Support corporate accounts and bulk bookings