要求:
1、执行完用户选择的功能后菜单继续展示
2、用户如果选择1 则在控制台输出如下内容
3、用户如果选择2 则提示用户输入办理入住的房间号和入住人姓名,并办理入住
4、用户如果选择3 则提示用户输入办理退房的房间号,并办理退房
5、用户如果选择4 则提示谢谢您的使用并结束系统
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean flag = true;
String[][] hotel = new String[6][5];
while(flag) {
System.out.println("-----xxx酒店管理系统-----");
System.out.println("1.查询房间");
System.out.println("2.办理入住");
System.out.println("3.办理退房");
System.out.println("4.退出");
System.out.println("请选择:");
int num = sc.nextInt();
switch(num){
case 1:
for(int i = 0; i < hotel.length; i++) {
for(int j = 0; j < hotel[i].length; j++) {
String roomName = "0"+(i+1)+"0"+(j+1);
String userName = hotel[i][j] == null? "空" :hotel[i][j];
System.out.print(roomName +":" +userName+";");
}
System.out.println();
}
break;
case 2:
System.out.println("请输入要入住的房间号: ");
int roomName = sc.nextInt();
System.out.println("请输入入住人的姓名: ");
String userName = sc.next();
int i = roomName / 100 - 1;
int j = roomName % 100 - 1;
if(i>=0 && i<hotel.length && j>=0 && j<hotel[i].length && hotel[i][j] == null) {
hotel[i][j] = userName;
System.out.println("办理入住成功!");
}else{
System.out.println("请输入正确的房间号或者无人入住的房间!");
}
break;
case 3:
System.out.println("请输入办理退房的房间号");
int roomName1 = sc.nextInt();
int i1 = roomName1 / 100 - 1;
int j1 = roomName1 % 100 - 1;
if(i1>=0 && i1<hotel.length && j1>=0 && j1<hotel[i1].length && hotel[i1][j1] != null) {
hotel[i1][j1] = null;
System.out.println("办理退房成功!");
}else {
System.out.println("请输入正确的房间号或者有人入住房间!");
}
break;
case 4:
flag = false;
System.out.println("感谢您的使用!!!");
break;
default:
System.out.println("请选择正确的选项!");
}
}
}