基于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