设计问题:预约系统

时间:2011-11-13 16:48:55

标签: java

我必须为酒店设计并实施预订系统。我有

  • 预订对象的数组列表
  • 房间对象的数组列表

我想在指定日期“保留”房间。

预订一个没有约会的房间会很容易,但它的日期部分会让它变得复杂。我正在努力设计这个并且自信地朝着正确的方向轻推我可以编码。

你怎么说在这个日期预订房间而不是在那个日期?

没有数据库或任何东西只是一个抽象的预订系统。

(我一直盯着这一段时间,请原谅我,如果解决方案很简单的话)

感谢。

4 个答案:

答案 0 :(得分:8)

创建三个类(before_create :set_current_store def set_current_store self.g_score_current = g_score_start end Hotel& Room):

  • Reservation对象在此处用作发票,并且与预订流程保持分离

  • 每个Reservation对象(专用于酒店中的每个房间号)都包含Room,其中map为关键字,reservedDates为值。

  • reservationObjectHotel组成。对于每个预订请求,rooms会循环显示Hotel列表,并且每个room遍历其自己的room,以查找是否可以预订天。

请注意,预订功能将日期作为列表,而不仅仅是两个日期(作为startDate和endDate)。与前者相同的是后者。

示例代码如下:

map

答案 1 :(得分:5)

编辑 - 第二个想法,为什么不让每个Room都有一个Reservation个实例列表,而这个实例又有一些开始/结束属性可以告诉你预订何时发生?

这样,为了判断一个房间是否有预约一段时间,你只需通过预订房间,看看有问题的时间是否在任何预订的开始/结束范围内......认为代码实现起来并不太容易(也不太难),但这是基本的想法。

答案 2 :(得分:1)

考虑一下, Room 是一种资源,您可以保留给定的时间范围。您还有几个房间可以独立预订。您将如何实现以下方法:

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

提示:房间必须知道其预订

从您的问题中不清楚预订的目的是什么。它只包含日期范围还是分配给特定房间?如果是前者,您可能会遇到为新预订找到空闲空间的问题 - 这可以通过循环所有房间并使用上述方法轻松实现。

如果是后者:由于预订知道房间,房间也可能知道预订。因此,通过迭代预留来实现上述方法是微不足道的。

答案 3 :(得分:0)

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);

}

}