package zjiudianguanlixitong;
//酒店房间
public class Room {
private String no;
private String type; //标准间 双人间 豪华间
private boolean isUse; //false表示空闲,true表示占用
public Room() {
super();
}
public Room(String no, String type, boolean isUse) {
super();
this.no = no;
this.type = type;
this.isUse = isUse;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isUse() {
return isUse;
}
public void setUse(boolean isUse) {
this.isUse = isUse;
}
public String toString(){
return "["+no+","+type+","+(isUse?"占用":"空闲")+"]";
}
}
package zjiudianguanlixitong;
public class Hotel {
//房间
Room[][] rooms;
//构造方法
Hotel(){
//5层,每层10个房间
rooms = new Room[5][10];
//赋值
//1,2 标准间
//3,4 双人间
//5 豪华间
for(int i = 0; i < rooms.length; i++){
for(int j = 0; j < rooms[i].length; j++){
if(i == 0 || i == 1){
rooms[i][j] = new Room(((i+1)*100)+j+1+"", "标准间", false);
}
if(i == 2 || i == 3){
rooms[i][j] = new Room(((i+1)*100)+j+1+"", "双人间", false);
}
if(i == 4){
rooms[i][j] = new Room(((i+1)*100)+j+1+"", "豪华间", false);
}
}
}
}
//对外提供一个打印酒店房间列表的方法
public void print(){
for(int i = 0; i < rooms.length; i++){
for(int j = 0; j < rooms[i].length; j++){
System.out.println(rooms[i][j] + " ");
}
System.out.println();
}
}
//对外提供一个预定酒店的方法
public void order(String no){
for(int i = 0; i < rooms.length; i++){
for(int j = 0; j < rooms[i].length; j++){
if(rooms[i][j].getNo().equals(no)){
//将该房间的状态改成占用
rooms[i][j].setUse(true);
return;
}
}
}
}
}
package zjiudianguanlixitong;
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
//初始化酒店
Hotel h = new Hotel();
//输出房间列表
h.print();
System.out.print("请输入预订酒店的房号");
String no = s.next();
//预订房间
h.order(no);
//打印酒店列表
h.print();
}
}