package other;
import java.util.Scanner;
public class HosMas {
Room r1 = new Room(1,"标准",true);
Room r2 = new Room(2,"标准",true);
Room r3 = new Room(3,"标准",true);
Room r4 = new Room(4,"豪华",true);
Room r5 = new Room(5,"豪华",true);
Room r6 = new Room(6,"豪华",true);
Room[][] room = {{r1,r2,r3},{r4,r5,r6}};
public void m1() {
HosMas hm1 = new HosMas();
System.out.println("订房请输入1,退房请输入2,查询某个房间状态请输入3,查询所有房间状态请输入4");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if(i == 1) { //调用订房方法
System.out.print("请输入要订的房间号:");
Scanner sc1 = new Scanner(System.in);
int id1 = sc1.nextInt();
hm1.m2(id1);
hm1.m1();
}else if(i == 2) { //调用退房方法
System.out.print("请输入退订的房间号:");
Scanner sc2 = new Scanner(System.in);
int id2 = sc2.nextInt();
hm1.m3(id2);
hm1.m1();
}else if(i == 3) { //调用查询方法
System.out.print("请输入要查询的房间号:");
Scanner sc3 = new Scanner(System.in);
int id3 = sc3.nextInt();
hm1.select(id3);
hm1.m1();
}else if(i == 4) { //调用查询所有方法
hm1.selectAll();
hm1.m1();
}else {
System.out.println("您输入的指令不正确,请重新输入!");
hm1.m1();
}
}
public static void main(String[] args) {
HosMas hm = new HosMas();
hm.m1();
}
public void select(int id) { // 查询某个房间的状态
for(int i = 0;i<room.length;i++) {
for(int j = 0;j<room[i].length;j++) {
if(id == room[i][j].id) {
System.out.println("房间号为"+id+"的信息如下");
System.out.println(room[i][j].id+room[i][j].type+room[i][j].state);
break;
}
}
}
}
public void selectAll() { // 查询所有房间的状态
for(int i = 0;i<room.length;i++) {
for(int j = 0;j<room[i].length;j++) {
System.out.println(room[i][j].id+" "+room[i][j].type+" "+room[i][j].state);
}
}
}
public void m2(int id) { //订房
for(int i = 0;i<room.length;i++) {
for(int j = 0;j<room[i].length;j++) {
if(id == room[i][j].id) {
room[i][j].state = false;
System.out.println("您已成功订购房间号为"+id+"房间");
break;
}
}
}
}
public void m3(int id) { //退房
for(int i = 0;i<room.length;i++) {
for(int j = 0;j<room[i].length;j++) {
if(id == room[i][j].id) {
if(room[i][j].state = true) {
System.out.println("此房间未被预定");
break;
}else {
System.out.println("您已成功退订房间号为"+id+"房间");
break;
}
}
}
}
}
}
控制台信息:
订房请输入1,退房请输入2,查询某个房间状态请输入3,查询所有房间状态请输入4
1
请输入要订的房间号:4
您已成功订购房间号为4房间
订房请输入1,退房请输入2,查询某个房间状态请输入3,查询所有房间状态请输入4
4
1 标准 true
2 标准 true
3 标准 true
4 豪华 true
5 豪华 true
6 豪华 true
订房请输入1,退房请输入2,查询某个房间状态请输入3,查询所有房间状态请输入4

为什么订房后,状态更改不了,酒店管理程序
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 未聞花名丶 2021-11-28 22:58关注
因为你每次调用m1方法 都新建了HosMas的实例,里面的状态都是最开始定义的
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报