用面向对象思想实现一个酒店管理系统,具体要求如下:java 50
1.Customername入住时间(String)入住天数编写构造方法和toString2.Room:房间编号,房间客户(Customer)(boolean)是否为空方...
1.Customer
name
入住时间(String)
入住天数
编写构造方法和toString
2.Room:
房间编号,
房间客户(Customer)
(boolean) 是否为空
方法:
入住
退房
3.Hotel:
楼层数
每层房间数
Room[][]数组
方法:
可根据房间编号查询房间
查询全部空房
4.Manager:可查询某个房间
查义全部空房
可入住,可退房 展开
name
入住时间(String)
入住天数
编写构造方法和toString
2.Room:
房间编号,
房间客户(Customer)
(boolean) 是否为空
方法:
入住
退房
3.Hotel:
楼层数
每层房间数
Room[][]数组
方法:
可根据房间编号查询房间
查询全部空房
4.Manager:可查询某个房间
查义全部空房
可入住,可退房 展开
1个回答
展开全部
package jcon.com.help;
/**
* 顾客类
* @author Jcon
*
*/
public class Customer {
private String name;
private String date;
private int days;
public Customer(String name, String date, int days) {
super();
this.name = name;
this.date = date;
this.days = days;
}
@Override
public String toString() {
return "Customer [name=" + name + ", date=" + date + ", days=" + days
+ "]";
}
}
package jcon.com.help;
/**
* 房间类
* @author Jcon
*
*/
public class Room {
private int number;
private Customer customer;
private boolean isUse = false;//开始房间是空的
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public boolean getIsUse() {
return isUse;
}
public void setIsUse(boolean isUse) {
this.isUse = isUse;
}
}
package jcon.com.help;
import java.util.HashMap;
import java.util.Map;
/**
* 酒店类
* @author Jcon
*
*/
public class Hote {
private int cengShu; //层楼
private int roomNumber; //每层楼房间数
public static Map<Integer,Room> rooms = new HashMap<Integer, Room>(); //key房间号,value房间信息
public Hote(int cengShu,int roomNumber) {
this.cengShu = cengShu;
this.roomNumber = roomNumber;
init();
}
private void init(){//初始化,把每个房间信息装入到Map
for (int i = 1; i <= this.cengShu; i++) {
for (int j = 1; j <= this.roomNumber; j++) {
String roomNumber = i+""+j;
if (j <10) {
roomNumber = i+"0"+j;
}
rooms.put(Integer.valueOf(roomNumber), new Room());
}
}
}
}
package jcon.com.help;
/**
* 酒店管理类
* @author Jcon
*
*/
public class Manager {
private Hote hote = new Hote(1, 15);
//通过房间号查找
public void findRoomByNumber(int roomNumber){
Room room = hote.rooms.get(roomNumber);
if (room == null) {
System.out.println("你要查找的房间号不存在,请确认输入房间号是否正确!");
}else {
if (room.getIsUse()){
System.out.println("房间:"+roomNumber+"已有人入住,入住人信息:"+room.getCustomer());
}else {
System.out.println("房间"+roomNumber+"还未有人入住");
}
}
}
//查找所有空房间
public void findNullRoom(){
for (Integer key : hote.rooms.keySet()) {
Room room = hote.rooms.get(key);
if (room.getIsUse() == false) {
System.out.println("空房间号:"+key);
}
}
}
//入住
public void in(int roomNumber,Customer customer){
Room room = hote.rooms.get(roomNumber);
room.setCustomer(customer);
room.setIsUse(true);
room.setNumber(roomNumber);
hote.rooms.put(roomNumber, room);
System.out.println("房间:"+roomNumber+"办理入住,住房人信息:"+customer);
}
//退房
public void out(int roomNumber){
Room room = hote.rooms.get(roomNumber);
room.setCustomer(null);
room.setIsUse(false);
hote.rooms.put(roomNumber, room);
System.out.println("房间:"+roomNumber+"办理退房");
}
public static void main(String[] args) {
Manager manager = new Manager();
//客人来开房,先看看有没有空房间
manager.findNullRoom();
//看到还有很多空房子,客人要开115号房
Customer customer = new Customer("小白", "03月25日入住", 3);//登记客人信息
manager.in(115, customer);//开房
//查看开房后当前房间信息
manager.findRoomByNumber(115); //115号房的
manager.findNullRoom(); //所有空房间的
//住了3天客人要退房
manager.out(115);
//查看退房后当前房间信息
manager.findRoomByNumber(115); //115号房的
manager.findNullRoom(); //所有空房间的
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询