Java实现简单酒店管理系统
作者:木子七七_qiqi 时间:2023-02-22 12:41:21
用Java编写一个简单的酒店管理系统,供大家参考,具体内容如下
为某个酒店编写程序:酒店管理系统,模拟订房、退房、打印所有房间状态等功能。
1、该系统的用户是:酒店前台。
2、酒店使用一个二维数组来模拟。“Room[][] rooms;”
3、酒店中的每一个房间应该是一个java对象:Room
4、每一个房间Room应该有:房间编号、房间类型、房间是否空闲.
5、系统应该对外提供的功能:
可以预定房间:用户输入房间编号,订房。
可以退房:用户输入房间编号,退房。
可以查看所有房间的状态:用户输入某个指令应该可以查看所有房间状态。
import org.w3c.dom.ls.LSOutput;
import java.util.Objects;
//测试
public class HotelTest {
public static void main(String[] args) {
Hotel h=new Hotel();
java.util.Scanner s=new java.util.Scanner(System.in);
System.out.println("欢迎使用酒店管理系统!请认真阅读以下功能。");
System.out.println("功能编号:1表示打印房间列表,2表示预定房间,3表示退订房间,4表示退出系统");
while(true){
System.out.println("请输入功能编号:");
int i=s.nextInt();
if(i==1){h.pri();}
else if(i==2){
System.out.println("请输入要预定的房间编号:");
h.order(s.nextInt());
}else if(i==3){
System.out.println("请输入要退订的房间编号:");
h.exit(s.nextInt());
}else if(i==4){
System.out.println("欢迎下次使用酒店管理系统,再见!");
return;
}else{
System.out.println("功能编号输入错误,请重新输入!");
}
}
}
}
//酒店管理系统
public class Hotel{
Room[][] rooms;
public Hotel(){
rooms=new Room[3][10];
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j <rooms[i].length ; j++) {
/*if(i==0){rooms[i][j]=new Room((i+1)*100+j+1,"单人间",true);}
if(i==1){rooms[i][j]=new Room((i+1)*100+j+1,"双人间",true);}
if(i==2){rooms[i][j]=new Room((i+1)*100+j+1,"三人间",true);}*/
rooms[i][j]=new Room();
rooms[i][j].setNo((i+1)*100+j+1);
rooms[i][j].setType(i==0?"单人间":(i==1?"双人间":"三人间"));
rooms[i][j].setStatus(true);
}
}
}
public void pri(){
for (int i = 0; i <rooms.length ; i++) {
for (int j = 0; j <rooms[i].length ; j++) {
System.out.print(rooms[i][j]);
}
System.out.println();
}
}
public void order(int no){
if(rooms[no/100-1][no%100-1].isStatus()==true) {
rooms[no / 100 - 1][no % 100 - 1].setStatus(false);
System.out.println(no + "号房间预订成功!");
}else{
System.out.println(no+"号房间已被预订,房间预订失败!");
}
}
public void exit(int no){
if(rooms[no/100-1][no%100-1].isStatus()==false) {
rooms[no / 100 - 1][no % 100 - 1].setStatus(true);
System.out.println(no + "号房间退订成功!");
}else{
System.out.println(no+"号房间已被退订,房间退订失败!");
}
}
}
//房间
public class Room{
private int no;
private String type;
private boolean status;
public Room() {
}
public Room(int no, String type, boolean status) {
this.no = no;
this.type = type;
this.status = status;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Room room = (Room) o;
return no == room.no;
}
@Override
public String toString() {
return "["+no+","+type+","+(status?"空闲":"占用")+"]";
}
}
来源:https://blog.csdn.net/weixin_47352351/article/details/114644936
标签:java,酒店,管理系统
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Mybatis Plus select 实现只查询部分字段
2022-07-23 18:51:32
![](https://img.aspxhome.com/file/2023/9/61279_0s.jpg)
Java线程的基本概念
2022-05-20 16:30:22
C#集合之并发集合的用法
2023-12-24 09:30:21
![](https://img.aspxhome.com/file/2023/8/106498_0s.jpg)
Eclipse转Itellij IDEA导入Git/svn本地项目的详细步骤
2021-11-06 12:57:10
![](https://img.aspxhome.com/file/2023/1/103821_0s.png)
jenkins+maven+svn自动部署和发布的详细图文教程
2023-08-24 05:18:07
![](https://img.aspxhome.com/file/2023/2/58442_0s.png)
C# DateTime.Compare()方法案例详解
2023-08-12 23:41:36
深入理解Javascript中的this关键字
2022-03-08 16:52:25
C#中4种深拷贝方法介绍
2023-01-02 21:16:11
C#中调用命令行cmd开启wifi热点的实例代码
2023-11-28 03:15:04
![](https://img.aspxhome.com/file/2023/0/96350_0s.jpg)
Java Exception 捕获和显示实例详解
2022-07-05 22:41:09
MyBatis-plus实现逆向生成器
2021-08-26 16:37:14
![](https://img.aspxhome.com/file/2023/0/122300_0s.png)
实例详解Java调用第三方接口方法
2023-10-15 06:34:32
![](https://img.aspxhome.com/file/2023/9/67469_0s.png)
Java 实战项目锤炼之网上商城系统的实现流程
2022-06-26 17:21:47
![](https://img.aspxhome.com/file/2023/3/97983_0s.jpg)
详解在LINUX上部署带有JAR包的JAVA项目
2022-12-30 21:07:14
![](https://img.aspxhome.com/file/2023/7/78427_0s.png)
IDEA不编译除了.java之外的文件的解决办法(推荐)
2023-09-16 15:50:44
![](https://img.aspxhome.com/file/2023/0/58570_0s.png)
Spring Boot如何通过自定义注解实现日志打印详解
2022-07-04 14:10:18
![](https://img.aspxhome.com/file/2023/1/78891_0s.png)
Spring Security中用JWT退出登录时遇到的坑
2022-05-19 10:30:28
![](https://img.aspxhome.com/file/2023/1/70921_0s.jpg)
Spring Boot静态资源路径的配置与修改详解
2022-09-15 19:27:08
判断图片-判断位图是否是黑白图片的方法
2023-06-09 17:20:07
Java面向对象之抽象类,接口的那些事
2022-08-25 19:16:30
![](https://img.aspxhome.com/file/2023/0/61530_0s.jpg)