Java实现简单的酒店管理系统
作者:梦小娴 时间:2022-05-10 01:32:12
本文实例为大家分享了java实现酒店管理系统的具体代码,供大家参考,具体内容如下
要求:
【酒店管理系统】HotelSystem.java
某酒店有12层楼,每层楼有10个房间(二维数组),要求为该酒店设计一套简单的前台房间管理程序,
该程序可以通过在命令行输入命令来为客人办理入住和退房手续。
要求该程序支持通过命令行输入以下命令来进行入住,退房及查询的操作:
(1)、search:查询所有房间的状态 无人住显示empty,有人则显示住户姓名
(2)、in 房间号码 姓名 :客人入住 命令:in 请输入客人入住的房间号 1202 请输入入住1202房间的顾客的姓
名 parker 提示:姓名为parker的客人入住1202房间
注意:如果某个房间已经有客人入住,在办理入住时,将提示“该房间已有客人入住”
(3)、out 房间号码:客人退房 命令:out 1202 提示:1202房间退房
(4)、quit:退出程序
实现:
import java.util.Scanner;
public class HotelSystem {
//房间数量
int[][] house=new int[12][10];
//住户姓名
String[] householdName=new String[120];
public HotelSystem()
{
Init();
}
//初始化数组
public void Init()
{
for(int i=0;i<12;i++)
{
for(int j=0;j<10;j++)
{
house[i][j]=0;
}
}
}
//查询
public void Search(HotelSystem hotel)
{
System.out.println("■■■■■■■■■■■■房间状态查询结果如下■■■■■■■■■■■■");
for(int i=0;i<12;i++)
{
for(int j=0;j<10;j++)
{
if(hotel.house[i][j]==0)
{
System.out.println(i*10+j+1+"号房间无人居住");
}
else if(hotel.house[i][j]==1)
{
System.out.println(i*10+j+1+"号房间"+hotel.householdName[i*10+j+1]+"在住");
}
}
}
}
//入住
public void InHouse(HotelSystem hotel,int housNums,String name,Scanner sc)
{
System.out.println("■■■■■■■■■■■■客人入住■■■■■■■■■■■■");
System.out.println("请输入客人入住的房间号");
housNums=sc.nextInt();
System.out.println("请输入入住"+housNums+"房间的顾客的姓名");
name=sc.next();
for(int i=0;i<12;i++)
{
for(int j=0;j<10;j++)
{
if(housNums==(i*10+j+1) && hotel.house[i][j]==0)
{
hotel.house[i][j]=1;
hotel.householdName[housNums]=name;
System.out.println("姓名为"+hotel.householdName[housNums]
+"的客人入住"+housNums+"号房间");
return;
}
else if(housNums==(i*10+j+1) && hotel.house[i][j]==1)
{
System.out.println("不好意思该房间已有客人入住");
return;
}
}
}
}
//退房
public void OutHouse(HotelSystem hotel,int housNums,Scanner sc)
{
System.out.println("■■■■■■■■■■■■客人退房■■■■■■■■■■■■");
System.out.println("请输入需要退房的房间号");
housNums=sc.nextInt();
for(int i=0;i<12;i++)
{
for(int j=0;j<10;j++)
{
if(housNums==(i*10+j+1) && hotel.house[i][j]==1)
{
hotel.house[i][j]=0;
System.out.println(housNums+"号房间成功退房");
return;
}
}
}
System.out.println("退房失败!");
}
//退出
public void Quit()
{
System.out.println("■■■■■■■■■■■■退出程序■■■■■■■■■■■■");
System.out.println("■■■■■■■■■■■■感谢使用,系统正在退出...■■■■■■■■■■■■");
}
public static void main(String[] args) {
HotelSystem hotel=new HotelSystem();
String command=null;
int housNums=0;
String name=null;
Scanner sc=new Scanner(System.in);
while(true)
{
System.out.println("■■■■■■■■■■■酒店管理系统命令■■■■■■■■■■■■■");
System.out.println("■■■■■■■■■■■1、search ■■■■■■■■■■■■■");
System.out.println("■■■■■■■■■■■2、in ■■■■■■■■■■■■■");
System.out.println("■■■■■■■■■■■3、out ■■■■■■■■■■■■■");
System.out.println("■■■■■■■■■■■4、quit ■■■■■■■■■■■■■");
System.out.println("请输入你需要执行的命令");
command=sc.next();
if(command.equals("search"))
{
hotel.Search(hotel);
}
else if(command.equals("in"))
{
hotel.InHouse(hotel, housNums, name, sc);
}
else if(command.equals("out"))
{
hotel.OutHouse(hotel, housNums, sc);
}
else if(command.equals("quit"))
{
hotel.Quit();
return;
}
}
}
}
关于管理系统的更多内容请点击《管理系统专题》进行学习
来源:https://blog.csdn.net/weixin_44350205/article/details/107600002
标签:java,酒店,管理系统
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaWeb中获取表单数据及乱码问题的解决方法
2021-11-21 11:03:53
![](https://img.aspxhome.com/file/2023/3/69673_0s.png)
Android 如何实现动态申请权限
2023-07-30 00:51:31
java自动生成编号的实现(格式:yyMM+四位流水号)
2023-10-10 09:24:36
SpringBoot配置SSL同时支持http和https访问实现
2023-04-25 19:42:45
![](https://img.aspxhome.com/file/2023/1/70521_0s.jpg)
Springboot实现Shiro整合JWT的示例代码
2022-01-30 02:58:32
![](https://img.aspxhome.com/file/2023/1/65601_0s.png)
JPA中EntityListeners注解的使用详解
2023-08-04 21:39:18
详解Spring ApplicationContext加载过程
2023-07-17 01:07:43
MyBatis映射文件resultMap元素中使用多个association的方法
2023-11-29 06:53:51
Android开发之DrawerLayout实现抽屉效果
2023-09-30 03:40:59
![](https://img.aspxhome.com/file/2023/5/85975_0s.png)
java基础的详细了解第四天
2022-11-25 07:24:51
![](https://img.aspxhome.com/file/2023/0/65350_0s.jpg)
Idea servlet映射方法优缺点对比
2023-06-12 23:59:34
![](https://img.aspxhome.com/file/2023/8/63298_0s.png)
Java接口的作用_动力节点Java学院整理
2021-12-23 20:46:14
![](https://img.aspxhome.com/file/2023/0/61570_0s.png)
SpringBoot中属性赋值操作的实现
2022-05-04 18:10:30
![](https://img.aspxhome.com/file/2023/3/70943_0s.png)
Java实现分解任意输入数的质因数算法示例
2022-07-29 23:07:08
![](https://img.aspxhome.com/file/2023/9/69349_0s.jpg)
C# form-data上传图片流到远程服务器的详细代码
2022-06-12 01:39:58
![](https://img.aspxhome.com/file/2023/9/70409_0s.png)
Android实现摇一摇功能
2023-07-23 20:21:11
Java深入浅出理解快速排序以及优化方式
2023-01-17 13:50:44
![](https://img.aspxhome.com/file/2023/9/69319_0s.jpg)
快速了解hibernate配置文件与映射文件
2023-11-04 23:02:26
浅析java实现数据加密问题
2023-03-21 02:54:04
Java多线程Atomic包操作原子变量与原子类详解
2023-08-18 07:46:25