Design an online hotel booking system

  • 15

    We have to design an online hotel booking system where a user can search a hotel in a given city and book it.

    My Solution :

    Main Classes :

    1. User
    2. Room
    3. Hotel
    4. Booking
    5. Adress
    Enums :
    public enum RoomStatus {
    public enum RoomType{
    public enum PaymentStatus {
    class User{
    int userId;
    String name;
    Date dateOfBirth;
    String mobNo;
    String emailId;
    String sex;
    // For the room in any hotel
    class Room{
    int roomId;
    int hotelId;
    RoomType roomType;
    RoomStatus roomStatus;
    class Hotel{
    int hotelId;
    String hotelName;
    Adress adress;
    List<Room> rooms; // hotel contains the list of rooms
    float rating;
    Facilities facilities;
    // a new booking is created for each booking done by any user
    class Booking{
        int bookingId;
        int userId;
        int hotelId; 
        List<Rooms> bookedRooms; 
        int amount;
        PaymentStatus status_of_payment;
        Time bookingTime;
        Duration duration;
    class Adress{
    string city;
    string pinCode;
    string streetNo;
    string landmark;
    class Duration{
    Time from;
    Tiime to;
    class Facilities{
    bool provides_lift;
    bool provides_power_backup;
    bool provides_hot_water;
    bool provides_breakfast_free;

  • 3

    @pooja_kamal, suppose there exists some hotel xyz which provides facility something other than those given in Facilities class. How to accommodate this new feature and show them to users. And any special reason why Facilities is a class? Cant we use enum for Facilities and use accordingly in Hotel class?

  • 0

    @pooja_kamal enum is fixed so that if we used enum. in this case we won't be able to add new facility

  • 1

    @mohamedabdallah_18 in case facility as class -> need to modify it to add new features.
    in case facility as enum -> need to modify the enum to add new features.
    we can have a List<Facility> in hotel class and Facility as enum. i think it's valid. correct me if missed something

  • 2

    I think decorator design pattern is useful to show facilities provided by hotel. There are so many facilities are possible. One hotel has any combination of those facility. List can be used but it is not suitable here according to me.

  • 0

    It is my first time practicing the ood question. I don't quite understand, why under hotel class, we use userid and hotelid of type int instead of user of type User and hotel of type Hotel, i thought thats the reason why we have those classes.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.