方便快捷易学的酒店管理系统
题目及要求:
酒店订房系统
- 订房时,如果输入房间号在酒店中不存在,要进行提示
- 退房时,如果输入房间号在酒店中不存在,要进行提示
- 订房或者退房时,如果操作错了,可以让他继续操作,不用直接显示主菜单
package Roobet;
import java.util.Scanner;
/**
* 酒店订房系统
* 订房时,如果输入房间号在酒店中不存在,要进行提示
* 退房时,如果输入房间号在酒店中不存在,要进行提示
* 订房或者退房时,如果操作错了,可以让他继续操作,不用直接显示主菜单
*/
public class T6 {
//定义酒店的楼层数
static int floor = 10;
//定义每层楼的房间数
static int room = 10;
//定义一个二维数组,用来存取房间的入住状态,若没人入住,填empty
static String [][] rooms = new String[floor][room];
//定义一个二维数组,用来存取入住客户的名字
static String [][] names = new String[floor][room];
//创建键盘扫描器
static Scanner key = new Scanner(System.in);
public static void main(String[] args) {
//初始化酒店房间状态
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j < rooms[i].length; j++) {
rooms [i][j] = "empty";//房间状态定为empty
}
}
//定义一个死循环,让系统处于一直运转的状态
while(true) {
help();
String h = key.next();
//h.equals("字符串"),比较输入的内容和括号中的是否一样
if (h.equals("search")) {
//查询房间的入住状态
searchRoom();
}else if (h.equals("in")) {
//预定房间
inTheRoom();
}else if (h.equals("out")) {
//退房
outTheRoom();
}else if (h.equals("exit")) {
//退出系统
System.out.println("客官慢走,欢迎下次光临!!");
break;
}
}
}
/*
* 退房系统管理
*/
private static void outTheRoom() {
System.out.println("请输入要退的房间号:");
int num = key.nextInt();
//如输入101号房间
int floor = num/100-1;
int room = num%100-1;
if (rooms[floor][room].equals("empty")) {
System.out.println("此房间无人入住,无需退房");
}else {
System.out.println("请输入您的姓名:");
String name = key.next();
if (names[floor][room].equals(name)) {
//判断输入的姓名和入住房间的姓名是否相等
//修改房间的入住状态为empty
rooms[floor][room] = "empty";
//将房间的姓名清空
names[floor][room] = null;
System.out.println("退房成功!");
}else {
//如果输入的名字和房间入住的名字不匹配
//无权利退房
System.out.println("对不起,不是本人没有权利退房,请谅解!");
}
}
}
/*
* 预定房间系统管理
*/
private static void inTheRoom() {
System.out.println("请输入你要预定的房间号:");
//接收输入的房间号
int num = key.nextInt();
int floor = num/100-1;
int room = num%100-1;
//查看输入的房间是否有人入住,若没有
if (rooms[floor][room].equals("empty")) {
System.out.println("请输入您的姓名:");
//接收输入的姓名
String name = key.next();
//修改房间的入住状态
rooms[floor][room] = "*****";
//保存名字
names[floor][room] = name;
System.out.println(name+"成功预定"+num+"号房间");
}else {
System.out.println("对不起,该房间已经有人预定了!!");
}
}
/*
* 查询房间的入住状态
*/
private static void searchRoom() {
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j < rooms[i].length; j++) {
System.out.print((i+1)*100+(j+1)+"\t");
}
System.out.println();
//遍历房间的入住状态
for (int j = 0; j < rooms[i].length; j++) {
System.out.print(rooms[i][j]+"\t");
}
System.out.println();
System.out.println("------------------------------------------------------------------------------");
}
}
private static void help() {
System.out.println("===============");
System.out.println("=欢迎来到‘喜迎宾’酒店=");
System.out.println("===============");
System.out.println("请选择操作");
System.out.println("==输入search查询酒店房间入住状态==");
System.out.println("==输入in预定房间====");
System.out.println("==输入out退房======");
System.out.println("==输入exit退出系统==");
System.out.println("=================");
System.out.println("请输入指令:");
}
}
运行结果如下: