1.每一个房间Room应该有:房间编号、房间类型、房间是否空闲
2.系统对外提供的功能:
2.1 可以预定房间
2.2 可以退房
2.3 可以查看所有房间的状态
package com.array2;
import java.util.Scanner;
/*
酒店信息管理系统
*/
public class HotelTest {
public static void main(String[] args) {
//创建房间对象,初始化此酒店房间信息
Room[][] rooms ={
{new Room(101,"单人间","空"),new Room(102,"单人间","空")},
{new Room(201,"双人间","空"),new Room(202,"双人间","空")},
{new Room(301,"豪华间","空"),new Room(302,"豪华间","空")}
};
//创建前台对象
stage s1 = new stage(rooms);
Scanner num = new Scanner(System.in);
int preId = num.nextInt();
//前台预定
s1.showPre(preId);
//前台退房
s1.showExit(preId);
//酒店实时状态
s1.showMenu();
}
}
//酒店前台类
class stage{
Room[][] r;
//构造方法
public stage(){}
public stage(Room[][] r){
this.r=r;
}
//前台预定
public void showPre(int id){
int height = id / 100;
int weight = id % 10;
r[height-1][weight-1].pre();
}
//前台退房
public void showExit(int id){
int height = id / 100;
int weight = id % 10;
r[height-1][weight-1].exit();
}
//前台展示房间状态
public void showMenu(){
for (int i = 0; i <r.length; i++) {
for (int j = 0; j <r[i].length; j++) {
r[i][j].show();
}
}
}
}
//房间类
class Room{
int id;
String type;
String full;
//构造方法
public Room(){}
public Room(int id,String type,String full){
this.id=id;
this.type=type;
this.full=full;
}
//房间预定
public void pre(){
this.full="有客";
}
//房间退房
public void exit(){
this.full="空";
}
//展示房间状态
public void show(){
System.out.println("房间号:"+this.id+",类型为:"+this.type+",此时状态为:"+this.full);
}
}
小白一枚,欢迎评论、给出建议和指出错误!