二维数组实现酒店管理系统

二维数组实现酒店管理系统

public class Room {
    int id;
    String  type;
    boolean isEmp;

    public Room(int id, String type, boolean isEmp) {
        this.id = id;
        this.type = type;
        this.isEmp=isEmp;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isEmp() {
        return isEmp;
    }

    public void setEmp(boolean emp) {
        isEmp = emp;
    }

    @Override
    public String toString() {
        return "["+id+type+(isEmp?"空闲":"已用")+"]";
    }
}
public class Hotel {

    Room[][] rooms = new Room[3][3];

    public Hotel() {
        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(100 * (i + 1) + j + 1, "标准间", true);
                } else if (i == 1) {
                    rooms[i][j] = new Room(100 * (i + 1) + j + 1, "单人间", true);
                } else if (i == 2) {
                    rooms[i][j] = new Room(100 * (i + 1) + j + 1, "总统套房", true);
                }
            }
        }
    }
    public void print() {
        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 getRoom(int RoomNo){
        Room room = rooms[RoomNo / 100 - 1][RoomNo % 100 - 1];
        room.isEmp=false;
        System.out.println("订房成功");
    }
    public void  exitRoom(int RoomNo){
        Room room = rooms[RoomNo / 100 - 1][RoomNo % 100 - 1];
        room.isEmp=true;
        System.out.println("退房成功");
    }
}
public class HotelText {
    public static void main(String[] args) {
        Hotel hotel=new Hotel();
        System.out.println("欢迎来到***酒店");
        System.out.println("1.[查看房间状态] 2.[订房] 3.[退房] 4.[退出]");
        while (true) {
            System.out.println("请输入操作");
            Scanner scanner = new Scanner(System.in);
            int i = scanner.nextInt();
            if (i == 1) {
                hotel.print();
            } else if (i == 2) {
                System.out.println("请输入订房编号");
                int x = scanner.nextInt();
                hotel.getRoom(x);
                System.out.println("订房成功");
            } else if (i == 3) {
                System.out.println("请输入退房编号");
                int x = scanner.nextInt();
                hotel.exitRoom(x);
                System.out.println("退房成功");
            } else if (i == 4) {
                System.exit(0);
            } else {
                System.out.println("输入错误");
            }
        }
    }
}



欢迎来到***酒店
1.[查看房间状态] 2.[订房] 3.[退房] 4.[退出]
请输入操作
1
[101标准间空闲][102标准间空闲][103标准间空闲]
[201单人间空闲][202单人间空闲][203单人间空闲]
[301总统套房空闲][302总统套房空闲][303总统套房空闲]
请输入操作
2
请输入订房编号
302
订房成功
订房成功
请输入操作
1
[101标准间空闲][102标准间空闲][103标准间空闲]
[201单人间空闲][202单人间空闲][203单人间空闲]
[301总统套房空闲][302总统套房已用][303总统套房空闲]
请输入操作
0
输入错误
请输入操作
4

Process finished with exit code 0

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值