使用二维数组 来管理酒店的 房间 状态 订房 退房 查询方法

使用二维数组 来管理酒店的 房间 状态 订房 退房 查询方法
刚刚学习Java 二维数据 写了一小时. 二维数组遍历判断 判断长度用了点时间
只是简单了 用了对象 类 ,刚刚学习.有研究2020 4月 有一起学习研究java的 私信我

package com.example.jiudianclass;public class Hotel {Room[][] mRooms;public Hotel(int h,int w) {mRooms = new Room[h][w];}public void addRoom(Room room){if (room == null){System.out.println("不能加入空房间信息");}mRooms[room.getH()-1][room.getW()-1]=room;//从房间对象获取 楼层与房间号 给二维数组}public Hotel() {}public void showRoom(){ ;// 二维数组遍历  取长度注意下for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {String str="房间号 "+mRooms[h][w].getRoomid();str+=" 类型 "+mRooms[h][w].getRoomType();str+=" 单价 "+mRooms[h][w].getMoney();str+="状态"+ (mRooms[h][w].isRoomFree()?" 有客 ":" 空闲 ");str+=mRooms[h][w].getH()+"楼"+mRooms[h][w].getW()+"号";System.out.println(str);}}}public void checkIn(String roomId){//房间号 订房for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {if(roomId.equals(mRooms[h][w].getRoomid())){mRooms[h][w].setRoomFree(true);//订房 有客改状态System.out.println(roomId+"已定房");}}}}public void checkOut(String roomId){//房间号 退房for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {if(roomId.equals(mRooms[h][w].getRoomid())){mRooms[h][w].setRoomFree(false);System.out.println(roomId+"已退房");}}}}
}
package com.example.jiudianclass;import java.util.Objects;public class Room {private String roomid;private String roomType;private int money;private boolean roomFree;private int w;private int h;public Room( String roomType, int money, boolean roomFree, int h, int w){this.roomid = "0"+h+"0"+w;this.roomType = roomType;this.money = money;this.roomFree = roomFree;this.w = w;this.h = h;}public Room() {}public int getW() {return w;}public void setW(int w) {this.w = w;}public int getH() {return h;}public void setH(int h) {this.h = h;}@Overridepublic int hashCode() {return Objects.hash(roomid, roomType, money, roomFree, w, h);}public String getRoomid() {return roomid;}public void setRoomid(String roomid) {this.roomid = roomid;}public String getRoomType() {return roomType;}public void setRoomType(String roomType) {this.roomType = roomType;}public int getMoney() {return money;}public void setMoney(int money) {this.money = money;}public boolean isRoomFree() {return roomFree;}public void setRoomFree(boolean roomFree) {this.roomFree = roomFree;}
}

使用二维数组 来管理酒店的 房间 状态 订房 退房 查询方法

使用二维数组 来管理酒店的 房间 状态 订房 退房 查询方法
刚刚学习Java 二维数据 写了一小时. 二维数组遍历判断 判断长度用了点时间
只是简单了 用了对象 类 ,刚刚学习.有研究2020 4月 有一起学习研究java的 私信我

package com.example.jiudianclass;public class Hotel {Room[][] mRooms;public Hotel(int h,int w) {mRooms = new Room[h][w];}public void addRoom(Room room){if (room == null){System.out.println("不能加入空房间信息");}mRooms[room.getH()-1][room.getW()-1]=room;//从房间对象获取 楼层与房间号 给二维数组}public Hotel() {}public void showRoom(){ ;// 二维数组遍历  取长度注意下for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {String str="房间号 "+mRooms[h][w].getRoomid();str+=" 类型 "+mRooms[h][w].getRoomType();str+=" 单价 "+mRooms[h][w].getMoney();str+="状态"+ (mRooms[h][w].isRoomFree()?" 有客 ":" 空闲 ");str+=mRooms[h][w].getH()+"楼"+mRooms[h][w].getW()+"号";System.out.println(str);}}}public void checkIn(String roomId){//房间号 订房for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {if(roomId.equals(mRooms[h][w].getRoomid())){mRooms[h][w].setRoomFree(true);//订房 有客改状态System.out.println(roomId+"已定房");}}}}public void checkOut(String roomId){//房间号 退房for (int h = 0; h < mRooms.length; h++) {for (int w = 0; w < mRooms[h].length; w++) {if(roomId.equals(mRooms[h][w].getRoomid())){mRooms[h][w].setRoomFree(false);System.out.println(roomId+"已退房");}}}}
}
package com.example.jiudianclass;import java.util.Objects;public class Room {private String roomid;private String roomType;private int money;private boolean roomFree;private int w;private int h;public Room( String roomType, int money, boolean roomFree, int h, int w){this.roomid = "0"+h+"0"+w;this.roomType = roomType;this.money = money;this.roomFree = roomFree;this.w = w;this.h = h;}public Room() {}public int getW() {return w;}public void setW(int w) {this.w = w;}public int getH() {return h;}public void setH(int h) {this.h = h;}@Overridepublic int hashCode() {return Objects.hash(roomid, roomType, money, roomFree, w, h);}public String getRoomid() {return roomid;}public void setRoomid(String roomid) {this.roomid = roomid;}public String getRoomType() {return roomType;}public void setRoomType(String roomType) {this.roomType = roomType;}public int getMoney() {return money;}public void setMoney(int money) {this.money = money;}public boolean isRoomFree() {return roomFree;}public void setRoomFree(boolean roomFree) {this.roomFree = roomFree;}
}