发布一个酒店管理系统代码,用javase数组等知识实现的
一个酒店管理系统要做到的基础操作有哪些?
1.房间状态的查询
2.预定入住
3.退房
4.及时更改酒店房间的信息
在这里我通过三个类实现的,一个房间类,一个方法类,一个测试类
房间类
package com.lh1029.hotel;
public class Room {
//房间的编号
private String id;
//房间的类型
private String type;
//房间是否以使用
private boolean isUse;
//一下代码都可以通过编译器生成,所以简单
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
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;
}
@Override
public String toString() {
return "[" + id + "," + type + "," + (isUse?"occupy":"leisure")+"]";
}
public Room(String i, String type, boolean isUse) {
this.id = i;
this.type = type;
this.isUse = isUse;
}
//构造方法
public Room() {
}
酒店类
package com.lh1029.hotel;
public class Hotel {
public Hotel() {
//创建room类,共60间房
room = new Room[6][10];
for(int i=0;i<room.length;i++){
for(int j=0;j<room[i].length;j++){
if(i==0||i==1){
room[i][j]=new Room((i+1)*100+j+1+"","Standard Room",false);
}
if(i==2||i==3) {
room[i][j]=new Room((i+1)*100+j+1+"","double room",false);
}
if(i==4||i==5) {
room[i][j]=new Room((i+1)*100+j+1+"","deluxe room ",false);
}
}
}
}
//打印房间列表状态
public void print(){
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 order(String id) {
for(int i=0;i<room.length;i++){
for(int j=0;j<room[i].length;j++) {
if(room[i][j].getId().equals(id)) {
room[i][j].setUse(true);
}
}
}
}
//退房
public void checkOut(String id) {
for(int i=0;i<room.length;i++){
for(int j=0;j<room[i].length;j++) {
if(room[i][j].getId().equals(id)) {
room[i][j].setUse(false);
}
}
}
}
}
测试类
package com.lh1029.hotel;
import java.util.Scanner;
public class Test {
private static Scanner s;
public static void main(String[] args) {
s = new Scanner(System.in);
System.out.println("Welcome to the hotel management system");
//创建一个酒店类
Hotel h=new Hotel();
//打印创建的房间列表
h.print();
//进入循环,订房/退房<->订房/退房
while(true) {
System.out.println("Please enter check-out or reservation");
//输入是退房还是订房,下面进行判断
String order =s.next();
if("reservation".equals(order)) {
System.out.println("Please enter the room number");
String id =s.next();
//输入入住id
h.order(id);
}else if("check-out".equals(order)) {
System.out.println("Please enter the room number");
String id =s.next();
//输入退房id
h.checkOut(id);
}else {
System.out.println("Please enter the room number");
}
//及时更新房间列表信息
h.print();
}
}
}//这里肯定不是最漂亮的代码,比较基础
版权声明:本文为weixin_46708745原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。