java快捷酒店管理系统_基于java的"酒店管理系统"

这是一个基于Java的简单酒店管理系统,包括房间初始化、查询、入住和退房功能。系统使用二维字符串数组表示12层楼每层10个房间的状态,并通过用户输入指令进行操作。
摘要由CSDN通过智能技术生成

2021-01-15

酒店管理系统

a7a313f4d60d8badb9ecfa8f5fe85a02.png

cbf649ba7535d9f3c150ca4bd28bf4f9.png

代码

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("你输入的房间号有误,请重新输入!");

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值