基於java的"酒店管理系統"


2021-01-15

酒店管理系統

代碼

  package Project;

  import jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment;

  import java.util.Scanner;

  /*
  //酒店前台管理系統
  一共有12層樓,每層10個房間
  通過命令來為客人辦理入住和退房手續
  1、insearch,查詢房間的狀態,空狀態empty
  2、in,辦理入住;找一個空的地址,賦予,需要輸入姓名,
  3、out,辦理退房;釋放該地址
  4、quit,退出系統,結束循環
   */
  public class HotelManagementSystem {
      public static void main(String[] args) {
          System.out.println("--------------------------------------------------");
          System.out.println("--------------" + "歡迎使用酒店管理系統" + "-----------------");
          System.out.println("--------------------------------------------------");
          Scanner sc = new Scanner(System.in);
          String[][] room = new String[12][10];
          init(room);//初始化酒店房間
          System.out.print("提示:");
          while (true) {
              System.out.println("輸入search 查詢所有房間;輸入 in 辦理入住; 輸入out 辦理退房; 輸入quit 關閉系統");
              System.out.print("請輸入指令:");
              String order = sc.next();
              if (order.equals("search")) {
                  System.out.println("查詢所有房間");
                  search(room);
              } else if (order.equals("in")) {
                  System.out.println("辦理入住");
                  in(room);
                    } else if (order.equals("out")) {
                  System.out.println("辦理退房");
                  out(room);
              } else if (order.equals("quit")) {
                  System.out.println("關閉系統");
                  break;
              } else {
                  System.out.println("請輸入正確的指令!");
              }
          }
      }

//房間初始狀態的方法
public static void init(String[][] room) {
    for (int i = 0; i < room.length; i++) {
        for (int j = 0; j < room[i].length; j++) {
            room[i][j] = "Empty";
        }
    }
    System.out.println("房間初始化成功!");
}

//查詢所有房間的方法
public static void search(String[][] room) {

    for (int i = 0; i < room.length; i++) {
        System.out.print("第" + (i + 1) + "樓");
        for (int j = 0; j < room[i].length; j++) {
            if (i < 9) {
                System.out.print("0");
            }
            int floor = (i + 1) * 100 + j + 1;
            System.out.print(floor + "\t");
        }
        System.out.println();
        //打印房間狀態
        for (int k = 0; k < room[i].length; k++) {
            System.out.print("\t" + room[i][k]);
        }
        System.out.println();
    }

}

//入住方法
public static void in(String[][] room) {
    boolean flag = true;
    System.out.print("請輸入您的姓名:");
    Scanner sc = new Scanner(System.in);
    String name = sc.next();
    /*
    1101 :11樓11樓,房間號1號
     */
    while (flag) {//當輸入的房間有人住時,繼續循環輸入房間,直到選擇一間沒有住的房間
        System.out.print("請輸入入住的房間號,例如203:");
        int rnum = sc.nextInt();
        int floor = rnum / 100 - 1;//樓層號
        int no = rnum % 100 - 1;//房間號
        if (floor >= 0 && floor <= 11 && no >= 0 && no <= 9) {//判斷輸入的房間號是否正確
            if (room[floor][no].equals("Empty")) {//判斷房間是否空的,如果空的,則入住,把入住的后房間狀態改為入住人姓名,然后結束            
                                                   循環
                room[floor][no] = name;
                flag = false;
            } else {//反之,繼續循環輸入房間號
                System.out.println("不好意思!這間房間有人入住了,請選擇別的房間!");
            }
        } else {
            System.out.println("輸入房間號不正確,請重新輸入!");
        }
    }
    System.out.println("歡迎入住!");
}

//退房方法
public static void out(String[][] room) {
    System.out.print("請輸入要退房的房間號,例如203:");
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();

    int floor = (num / 100) - 1;
    int no = (num % 100) - 1;
    if (floor >= 0 && floor <= 11 && no >= 0 && no <= 9) {//判斷輸入的房間號是否正確
        if (room[floor][no].equals("Empty")){
            System.out.println("房間為空房,不需要退房");}
        else {
            room[floor][no] = "Empty";
            System.out.println("恭喜您退房成功,歡迎下次再來");
        }
    }else{
        System.out.println("你輸入的房間號有誤,請重新輸入!");
    }



}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM