Java代码实现酒店管理系统(基于java的宾馆客房管理系统)
405
2022-07-28
用java编写一个简单的酒店管理系统,供大家参考,具体内容如下
为某个酒店编写程序:酒店管理系统,模拟订房、退房、打印所有房间状态等功能。
1、该系统的用户是:酒店前台。2、酒店使用一个二维数组来模拟。“Room[][] rooms;”3、酒店中的每一个房间应该是一个java对象:Room4、每一个房间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 /*if(i==0){rooms[i][j]=new Room((i+1)*1EovfmH00+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].EovfmHsetType(i==0?"单人间":(i==1?"双人间":"三人间")); rooms[i][j].setStatus(true); } } } public void pri(){ for (int i = 0; i for (int j = 0; 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 bhttp://oolean 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?"空闲":"占用")+"]"; } }
/*if(i==0){rooms[i][j]=new Room((i+1)*1EovfmH00+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].EovfmHsetType(i==0?"单人间":(i==1?"双人间":"三人间"));
rooms[i][j].setStatus(true);
}
}
}
public void pri(){
for (int i = 0; i for (int j = 0; 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 bhttp://oolean 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?"空闲":"占用")+"]"; } }
for (int j = 0; 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 bhttp://oolean 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?"空闲":"占用")+"]"; } }
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 bhttp://oolean 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?"空闲":"占用")+"]";
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~