Skip to main content

Design a Hotel Management/Booking System

Problem Statement

Design a hotel management system that allows guests to book rooms, check room availability, cancel bookings, and manage hotel rooms efficiently. The design should support multiple room types and ensure that a room cannot be booked by multiple guests at the same time.


Functional Requirements

  • The design should support multiple room types such as standard, deluxe, and suite
  • Guests should be able to search available rooms
  • A guest should be able to book a room
  • A booked room should not be assigned to another guest
  • The design should support booking cancellation
  • Cancelled rooms should become available again
  • The design should maintain booking details for every guest
  • The system should support multiple hotels and rooms

Objects Required

  • Hotel
  • Room
  • RoomType
  • Guest
  • Booking
  • BookingStatus
  • HotelManagementSystem

RoomType Enum


public enum RoomType {
    STANDARD,
    DELUXE,
    SUITE
}

The RoomType enum defines the supported room categories inside the hotel.

Using an enum avoids invalid room types and keeps comparisons simple throughout the booking flow.


BookingStatus Enum


public enum BookingStatus {
    CONFIRMED,
    CANCELLED
}

The BookingStatus enum represents the current state of a booking.


Room Class

The Room class represents an individual room inside the hotel.


public class Room {

    private int roomNumber;
    private RoomType type;
    private boolean isAvailable;

    public Room(int roomNumber, RoomType type) {
        this.roomNumber = roomNumber;
        this.type = type;
        this.isAvailable = true;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public void bookRoom() {
        isAvailable = false;
    }

    public void releaseRoom() {
        isAvailable = true;
    }

    public RoomType getType() {
        return type;
    }

    public int getRoomNumber() {
        return roomNumber;
    }
}

The constructor initializes the room number, room type, and marks the room as available initially.

The isAvailable() method checks whether the room is currently free.

The bookRoom() method marks the room as occupied after successful booking.

The releaseRoom() method makes the room available again when the booking is cancelled or completed.

The getter methods provide controlled access to room details.


Guest Class

The Guest class stores guest related information.


public class Guest {

    private String guestId;
    private String name;

    public Guest(String guestId, String name) {
        this.guestId = guestId;
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

The constructor initializes the guest with an id and name.

The getName() method is used whenever guest details are required during booking or display operations.


Booking Class

The Booking class stores details about a room reservation.


public class Booking {

    private String bookingId;
    private Guest guest;
    private Room room;
    private BookingStatus status;

    public Booking(String bookingId,
                   Guest guest,
                   Room room) {

        this.bookingId = bookingId;
        this.guest = guest;
        this.room = room;
        this.status = BookingStatus.CONFIRMED;
    }

    public void cancelBooking() {

        room.releaseRoom();
        status = BookingStatus.CANCELLED;
    }
}

The constructor creates a booking object and stores the associated guest and room information.

The booking status is initially marked as CONFIRMED.

The cancelBooking() method releases the booked room and updates the booking status to CANCELLED.


Hotel Class

The Hotel class manages rooms available inside a hotel.


import java.util.*;

public class Hotel {

    private String hotelName;
    private List<Room> rooms;

    public Hotel(String hotelName,
                 List<Room> rooms) {

        this.hotelName = hotelName;
        this.rooms = rooms;
    }

    public List<Room> getAvailableRooms(RoomType type) {

        List<Room> availableRooms =
                new ArrayList<>();

        for (Room room : rooms) {

            if (room.isAvailable()
                    && room.getType() == type) {

                availableRooms.add(room);
            }
        }

        return availableRooms;
    }
}

The constructor initializes the hotel with its rooms.

The getAvailableRooms() method filters rooms based on room type and availability.

Only rooms matching the requested category and currently available are returned to the user.


HotelManagementSystem Class

The HotelManagementSystem class coordinates the booking process.


import java.util.*;

public class HotelManagementSystem {

    private List<Hotel> hotels;

    public HotelManagementSystem(List<Hotel> hotels) {
        this.hotels = hotels;
    }

    public Booking bookRoom(Guest guest,
                            Hotel hotel,
                            RoomType roomType) {

        List<Room> availableRooms =
                hotel.getAvailableRooms(roomType);

        if (availableRooms.isEmpty()) {

            System.out.println("No rooms available");
            return null;
        }

        Room room = availableRooms.get(0);

        room.bookRoom();

        return new Booking(
                UUID.randomUUID().toString(),
                guest,
                room
        );
    }
}

The constructor initializes the system with available hotels.

The bookRoom() method first searches for available rooms of the requested type.

If no room is available, the booking request fails immediately.

If rooms are available, the first matching room is selected and marked as booked.

Finally, a booking object is created with a unique booking id.


Main Class

The Main class is used to simulate the hotel booking flow.


import java.util.*;

public class Main {

    public static void main(String[] args) {

        List<Room> rooms = Arrays.asList(
                new Room(101, RoomType.STANDARD),
                new Room(102, RoomType.DELUXE),
                new Room(103, RoomType.SUITE)
        );

        Hotel hotel =
                new Hotel("Grand Palace", rooms);

        HotelManagementSystem system =
                new HotelManagementSystem(
                        Arrays.asList(hotel)
                );

        Guest guest =
                new Guest("G1", "Prasanna");

        Booking booking =
                system.bookRoom(
                        guest,
                        hotel,
                        RoomType.DELUXE
                );

        if (booking != null) {
            System.out.println("Room booked successfully");
        }

        booking.cancelBooking();

        System.out.println("Booking cancelled");
    }
}

The main() method starts by creating hotel rooms of different types.

A hotel object is then initialized with those rooms.

The booking system receives a booking request from the guest and allocates a matching room if available.

Finally, the booking is cancelled to demonstrate how the room becomes available again.


Class Diagram

RoomTypeSTANDARDDELUXESUITEBookingStatusCONFIRMEDCANCELLEDRoomroomNumber : inttype : RoomTypeisAvailable : booleanisAvailable() : booleanbookRoom() : voidreleaseRoom() : voidgetType() : RoomTypegetRoomNumber() : intGuestguestId : Stringname : StringgetName() : StringBookingbookingId : Stringguest : Guestroom : Roomstatus : BookingStatuscancelBooking() : voidHotelhotelName : Stringrooms : List<Room>getAvailableRooms(type : RoomType) : List<Room>HotelManagementSystemhotels : List<Hotel> hotel : Hotel,bookRoom(guest : Guest,roomType : RoomType) : BookingMainmain(args : String[]) : void

Also See

Comments

Popular posts from this blog

Designing a Parking Lot - Low Level Design

Problem Statement Design a parking lot that can handle vehicles entering and leaving while managing parking across multiple floors. Each vehicle should be assigned a suitable parking spot based on its type, and the spot should be freed once the vehicle exits. The design should also support generating a ticket at entry and optionally calculating the parking fee based on the duration of stay. Asked In Companies Amazon Google Microsoft Uber Walmart Flipkart Meta PayPal Oracle Salesforce Adobe Apple Intuit LinkedIn Atlassian Functional Requirements The design should support multiple vehicle types such as bikes, cars, and trucks A vehicle must be assigned a parking spot compatible with its type A parking spot cannot be assigned to more than one vehicle at a time The parking lot should support multiple levels (floors) The design should search and allocate an availa...

Most Frequently Asked Low Level Design(LLD) Interview Questions

Below are the curated list of most commonly asked Low Level Design (LLD) interview problems. Each problem includes a short description and a link to the complete solution with code and class diagrams. Design Parking Lot System The system should handle parking for different vehicle types such as bikes, cars, and trucks. It should manage slot allocation, availability tracking, and entry/exit flow. The design also ensures efficient usage of parking space under varying load conditions. View Solution Design Elevator / Lift System The system should support multiple elevators operating across floors with request handling logic. It focuses on scheduling algorithms to minimize wait time and optimize movement. It also manages direction control and concurrent floor requests. View Solution Design Movie Ticket Booking System The system should allow users to browse movies, select shows, and book seats. It handles seat ...

Software Design Patterns for LLD Interviews: A Complete Guide

Software Design Patterns for LLD Interviews: A Complete Guide In Software Development Engineer (SDE) interviews—especially for mid-level and senior roles—low-level design (LLD) rounds assess your ability to write clean, reusable, maintainable, and extensible code. The foundation of resolving these architectural challenges lies in the standard Gang of Four (GoF) Design Patterns. Rather than memorizing theoretical definitions, interviewers expect you to apply these patterns to real-world scenarios, identifying the trade-offs of each. Below is a comprehensive guide to the 12 most frequently asked design patterns in LLD interviews, categorized by their classification (Creational, Structural, and Behavioral). Each pattern contains a concrete, real-world Java implementation and a detailed breakdown of design decisions. Creational Design Patterns Creational design patterns deal with object creation mechanisms. They abstract the instantiation process, making a system independent of how...