======思路======

======实现======

======代码======

import java.util.Scanner;
public class Reception {
public static void main(String[] args) {
//首先来一条友善的系统名称
System.out.println("****东方国际大酒店管理系统*****"+"\t\n");
Hotel hotel=new Hotel();//新建酒店类,以便调用酒店类的方法
Scanner in=new Scanner(System.in);//系统接受前台人员输入指令

while(true) { System.out.println("订房输入 1; 退房输入 2:"); int input=in.nextInt();//保存前台人员输入指令 if (input==1) {//判断是否是“订房” System.out.println("********************客房信息*************************"+"\t\n"); hotel.checkRoomInfo();//显示客房最新信息 System.out.println("\t\n"+"*****************************************************"+"\t\n"); System.out.println("入住的客房号:"); int cin=in.nextInt();//保存前台人员输入指令 hotel.checkIn(cin);//把指令传给酒店类的订房方法去处理 } else if (input==2) {//判断是否是“退房” System.out.println("********************客房信息*************************"+"\t\n"); hotel.checkRoomInfo();//显示客房最新信息 System.out.println("\t\n"+"*****************************************************"+"\t\n"); System.out.println("退房的客房号:"); int con=in.nextInt();//保存前台人员输入指令 hotel.checkOut(con);//把指令传给酒店类的退房方法去处理 }else System.out.println("********************客房信息*************************"+"\t\n"); hotel.checkRoomInfo();//显示客房最新信息 System.out.println("\t\n"+"*****************************************************"+"\t\n"); }}

}

public class Room {
//房间编号
private int roomNum;
//房间类型
private String roomType;
//房间状态
private boolean roomStatus;

//房间属性的get,set方法public int getRoomNun() { return roomNum;}public void setRoomNun(int roomNun) { this.roomNum = roomNun;}public String getRoomType() { return roomType;}public void setRoomType(String roomType) { this.roomType = roomType;}public boolean isRoomStatus() { return roomStatus;}public void setRoomStatus(boolean roomStatus) { this.roomStatus = roomStatus;}//构造方法public Room(int roomNun, String roomType, boolean roomStatus) { super(); this.roomNum = roomNun; this.roomType = roomType; this.roomStatus = roomStatus;}//重写toString方法@Overridepublic String toString() { return "【" + roomNum + ":" + roomType + ":" + (roomStatus?"客满":"空房" )+ "】 ";}

}

public class Hotel {
//声明一个数组来记录酒店的楼层和客房
Room[][] room;
//酒店类构造方法
public Hotel() {
//二维数组定义酒店6层楼,每层楼8间客房
room =new Room[6][8];
//嵌套循环把各个房间的属性初始化
for(int i=0;i<room.length;i++) {//楼层
for(int j=0;j<room[i].length;j++) {//客房
//1,2层标准房, 客房编号101,102....201,202....601,602.....608
if(i==0||i==1) {
room[i][j]=new Room((i+1)100+j+1,"标准房",false);
}
//3,4层贵宾房
else if(i==2||i==3) {
room[i][j]=new Room((i+1)
100+j+1,"贵宾房",false);
}
//5,6层总统房
else if(i==4||i==5) {
room[i][j]=new Room((i+1)*100+j+1,"总统房",false);
}
}
}
}
//查看客房信息
public void checkRoomInfo() {
for(int i=0;i<room.length;i++) {//楼层
for(int j=0;j<room[i].length;j++) {//客房
System.out.print(room[i][j]);//同一层客房不换行显示
}
System.out.println();//不同楼层的客房信息换行显示
}
}
//客人订房
public void checkIn(int roomNum) {
for(int i=0;i<room.length;i++) {
for(int j=0;j<room[i].length;j++) {
if(room[i][j].getRoomNun()==roomNum) {
room[i][j].setRoomStatus(true);//如果客人订房,就把相应人房间的状态设置为客满。
}
}
}
}
//客人退房
public void checkOut(int roomNum) {
for(int i=0;i<room.length;i++) {
for(int j=0;j<room[i].length;j++) {
if(room[i][j].getRoomNun()==roomNum) {
room[i][j].setRoomStatus(false);//如果客人退房,就把相应人房间的状态设置为空房。
}
}
}
}
}

博主个人网站:www.davis-wiki.com