Design Issues: Booking System

I need to develop and implement a reservation system for a hotel. I have

  • list of arrays of reservation objects
  • list of objects in rooms

I want to reserve a room for a specific date.

To book a room without a date would be easy, but this is part of the date that complicated it. I am struggling with the design of this and confidently pushing in the right direction, I could code it.

How do you say that the room is reserved for this date, but not for this date?

There is no database or anything else its abstract backup system.

(I looked at this for a while, sorry if this is easy to solve)

Thank.

+8
source share
4

EDIT - -, Room Reservation, , , , , ?

, , - , , , ... ( ) , .

+5

(Hotel, Room Reservation):

  • Reservation - , .

  • Room ( ) map, reservedDates reservationObject .

  • Hotel rooms. Hotel Room, Room map, , .

, , ( startDate endDate). , , .

:

class Hotel {
    private String name, address;
    private List<Room> roomList;   //key : roomNumber
    public Hotel(){
        roomList = new ArrayList<Room>();
    }
    public Reservation bookRoomForDates(List<Integer> dateList, Guest guest){
        for(Room room : roomList){
            Reservation reservation = room.bookForGivenDates(dateList, guest);
            if(reserved != null) return reservation; //Reservation successFull!
        }
        return null; //Reservation failed!
    }
}
class Reservation {
    private String id;
    private Date inDate, outDate;
    private Guest guest;

    public Reservation(Room room, int startDate, int endDate, Guest guest){
        //populate the member variables.
    }
}

class Room {
    private String id;
    private int roomNumber, floorNum;
    private Map<Integer, Reservation> reservedDates;  // key : date as Integer (YYYYMMDD)

    public Room(int roomNumber){
        reservedDates = new HashMap<Integer, Reservation>();
        this.roomNumber = roomNumber;
    }

    //A guest request for booking on dates(in YYYYMMDD format) in the dateList
    public Reservation bookForGivenDates(List<Integer> dateList, Guest guest)  
    {   
        if(dateList.isEmpty()) return null;

        for(Integer date : dateList){
            Reservation res = reservedDates.get(date);  
            if(res != null) {  // We don't store null value for unreserved dates for the room.
                return null;  // Room is reserved on this date by another guest. So, this room is unavailable.
            }
        }
        //this room is unreserved on all requested dates. So go on and reserve this room for asked dates
        int startDate = dateList.get(0);
        int endDate   = dateList.get(dateList.size() - 1);

        Reservation newReservation = new Reservation(this, startDate, endDate, guest);
        for(Integer date : dateList){
            reservedDates.put(date, newReservation);
        }
        return newReservation;
    }
}
+8

, Room - , . , . :

class Room {
  boolean isAvailable(Date date) {/*...*/}
  Date nextAvailableDate() {/*...*/}
}

: .

, . ? , - , .

: , . , , .

+1
import java.util.*;

public class Final_Project {

public static void main(String[] args) {

    Scanner ScanObj = new Scanner(System.in);
    String choice="";
            int a=1;
            int x;
            int stay=0;
             int totalBill;
            String name="";
            String num="";
    String checkIn="";
            String checkOut="";

    System.out.println("Kindly Fillup");

            Date d = new Date();




    System.out.print("Name:");
    name = ScanObj.nextLine();

    System.out.print("Phone Number:");
    num =ScanObj.nextLine();

            System.out.print("Check-in: ");
            checkIn = ScanObj.nextLine();

    System.out.print("Check-Out: ");
            checkOut = ScanObj.nextLine();



    System.out.println("Hello," + name + ". Welcome to Kimberly Hotel");
do{ 
    try{

    for(x=1; x==1;) {

        System.out.println("[1] Room Reservations");

    for(x=1; x==1;) {

        System.out.print("ENTER : ");
        choice=ScanObj.nextLine();

            if (choice.equals("1")) {
                System.out.println("            Rooms");
                System.out.println("*********************************");
                System.out.println("1.)Room 101   | Php 10,000 |5 Persons");
                System.out.println("2.)Room 102   | Php 8,000 |4 Persons");
                System.out.println("3.)Room 103   | Php 6,500 |3 Persons");
                System.out.println("4.)Room 104   | Php 5,000 |2 Persons");
                System.out.println("5.)Room 105   | Php 5,000 |2 Persons");
                x=0;

            }

            else
                throw new InputMismatchException("");
                a=2;
        }
    }
}catch(Exception e) {

        System.out.println("Invalid Input. Please try again.");

        }

}while(a==1);

int choices;
int control=1;
do{

    try{

        System.out.print("Please select a room: ");
        choices = ScanObj.nextInt();

                    System.out.print("How long will you stay: ");
                    stay = ScanObj.nextInt();



        switch(choices) 
        {
        case 1:
            System.out.println("Here is your reservation as of: " + d.toString());
            System.out.println(name+" |"+num+"|1 Room 101 | Php 10,000 | 5 Persons|");
                            System.out.println("Check-in Date: " + checkIn);
                            System.out.println("Check-Out Date: " + checkOut);
                            totalBill = stay * 10000;
                            System.out.println("Your total bill is: " + totalBill);
                            System.out.println("Additional 2 beddings");
                            System.out.println("Free Breakfast");
                            System.out.println("No pets allowed!");
                            System.out.println("Thank You!");
            break;
        case 2:
                            System.out.println("Here is your reservation as of: " + d.toString());
            System.out.println("Here is your reservation: ");
            System.out.println(name+" |"+num+"| Room 102  | Php 8,000 | 4 Persons|");
                            System.out.println("Check-in Date: " + checkIn);
                            System.out.println("Check-Out Date: " + checkOut);
                            totalBill = stay * 8000;
                            System.out.println("Your total bill is: " + totalBill);
                            System.out.println("Additional 2 beddings");
                            System.out.println("Free Breakfast");
                            System.out.println("No pets allowed!");
            System.out.println("Thank You!");
                            break;
        case 3:
                            System.out.println("Here is your reservation as of: " + d.toString());
            System.out.println("Here is your reservation: ");
            System.out.println(name+" |"+num+"| Room 103  | Php 6,500 | 3 Persons|");
                            System.out.println("Check-in Date: " + checkIn);
                            System.out.println("Check-Out Date: " + checkOut);
                            totalBill = stay * 8000;
                            System.out.println("Your total bill is: " + totalBill);
                            System.out.println("Additional 2 beddings");
                            System.out.println("Free Breakfast");
                            System.out.println("No pets allowed!");
                            System.out.println("Thank You!");
            break;
        case 4:
                            System.out.println("Here is your reservation as of: " + d.toString());
            System.out.println("Here is your reservation: ");
            System.out.println(name+" |"+num+"| Room 104  | Php 5,000 | 2 Persons|");
                            System.out.println("Check-in Date: " + checkIn);
                            System.out.println("Check-Out Date: " + checkOut);
                            totalBill = stay * 8000;
                            System.out.println("Your total bill is: " + totalBill);
                            System.out.println("Additional 1 beddings");
                            System.out.println("Free Breakfast");
                            System.out.println("No pets allowed!");
                            System.out.println("Thank You!");
            break;
        case 5:
                            System.out.println("Here is your reservation as of: " + d.toString());
            System.out.println("Here is your reservation: ");
            System.out.println(name+" |"+num+"| Room 105  | Php 5,000 | 2 Persons|");
                            System.out.println("Check-in Date: " + checkIn);
                            System.out.println("Check-Out Date: " + checkOut);

                            System.out.println("Additional 1 beddings");
                            System.out.println("Free Breakfast");
                            System.out.println("No pets allowed!");
                            System.out.println("Thank You!");
            break;

        default:
        System.out.println("Number"+" "+choices + " is not given. Please select within the given rooms.");
        throw new InputMismatchException("");

        }
        control=2;

    }catch(InputMismatchException ex) {

    }


}while(control==1);

        System.out.println("");
        int choicess;
        boolean b=true;
    do{
        try{

                System.out.println("[1] CANCEL");
                System.out.println("[2] RESERVE");


        System.out.println("Select from above: ");  
        choicess=ScanObj.nextInt();

        switch(choicess)    
        {
        case 1:
            System.out.println("Cancellation Done Thanks!");
            break;
        case 2:
            System.out.print("Your hotel room has been successfully reserved. Thank you!");
            break;
        default:
            System.out.println("Error. Please select within the given numbers.");
            System.out.println("Thank you!");
            throw new InputMismatchException("");

        }
        b=false;

    }catch(Exception exx) {

        System.out.println("");


    }

    }while(b!=false);

}

}

0

All Articles