Java課程作業(yè),酒店管理系統(tǒng)由前臺(tái)系統(tǒng)實(shí)現(xiàn)主要功能,具備以下功能:
目錄
?Room
Customer
CheckList
Hotel
HotelSystem
?Room
Room類,包含了房間號(hào),房間類型,房間狀態(tài)(住宿還是空閑),房間價(jià)格,以及入住人信息。
//Room 類
import java.util.Objects;
public class Room{
private int roomnumber;
public String type;
private int status;//房間狀態(tài),1:入??;0:空閑;-1:被預(yù)訂
private int price;
public Customer customerInfo = new Customer();
public Room() {
}
public Room(int roomnumber, String type, int status,int price) {
this.roomnumber = roomnumber;
this.type = type;
this.status = status;
this.price = price ;
}
public int getRoomnumber() {return roomnumber;}
public void setRoomnumber(int roomnumber) {this.roomnumber = roomnumber;}
public String getType() {return type;}
public void setType(String type) {this.type = type;}
public int getStatus() {return status;}
public void setStatus(int status) {this.status = status;}
public int getPrice() {return price;}
public void setPrice(int price) {this.price = price;}
//重寫toString方法,可以轉(zhuǎn)換成輸出房間信息
@Override
public String toString() {
String roominfo = new String();
switch(status)
{
case 0 :
roominfo = "ROOM信息{"+roomnumber+","+type+","+"空閑"+"}";
break;
case 1:
roominfo = "ROOM信息{"+roomnumber+","+type+","+"已滿"+"}";
break;
case -1:
roominfo = "ROOM信息{"+roomnumber+","+type+","+"已預(yù)訂"+"}";
break;
}
return roominfo;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Room room = (Room) o;
return roomnumber== room.roomnumber && status == room.status && Objects.equals(type, room.type);
}
public int hashCode() {
return Objects.hash(roomnumber, status, type,price);
}
}
Customer
Customer類,用于實(shí)現(xiàn)顧客屬性。
public class Customer {
public String cname;
public int age;
public String cid;
public String phone;
public int pay;
public int getPay() {return pay;}
public void setPay(int pay) {this.pay = pay;}
public int getAge() {return age;}
public void setAge(int age) {this.age = age;}
public String getName() {return cname;}
public void setName(String name) {this.cname = name;}
public String getPhone() {return phone;}
public void setPhone(String phone) {this.phone = phone;}
public String getId() {return cid;}
public void setId(String id) {this.cid = id;}
public void customer(String customerName, int customerAge, String customerId, String customerphone)
{
this.cname = customerName;
this.age = customerAge;
this.cid = customerId;
this.phone = customerphone;
}
}
CheckList
這個(gè)是老師讓改的一部分,對(duì)于查詢記錄的類
//記錄類
public class CheckList
{
private Room room;
public Date startTime;
public CheckList(Room room,Date startTime)
{
this.room = room;
this.startTime =startTime;
}
public Room getRoom()
{
return room;
}
public void setRoom(Room room)
{
this.room = room;
}
public Date getStartTime()
{
return startTime;
}
public void setStartTime(Date startTime)
{
this.startTime = startTime;
}
}
//入住記錄類
class CheckInList extends CheckList
{
public CheckInList(Room room, Date startTime) {
super(room, startTime);
}
}
//歷史記錄類
class CheckOutList extends CheckList
{
public Date endTime;
public CheckOutList(Room room,Date startTime,Date endTime)
{
super(room,startTime);
this.endTime = endTime;
}
public Date getEndTime()
{
return startTime;
}
public void setEndTime(Date endTime)
{
this.endTime = endTime;
}
}
Hotel
主要功能酒店類,實(shí)現(xiàn)以上菜單內(nèi)的所有功能
import java.text.SimpleDateFormat;
import java.util.*;
public class Hotel {
private Room[][] room;
public ArrayList<CheckList> checkList = new ArrayList<CheckList>();
public ArrayList<CheckOutList> historyList = new ArrayList<CheckOutList>();
public static Scanner sc = new Scanner(System.in);
public static SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public Hotel()
{
room = new Room[5][10];
for(int i=0;i < room.length;i++){
for(int j =0 ;j < room[i].length;j++){
if(i==0){
room[i][j] = new Room((i+1)*100+j+1,"標(biāo)準(zhǔn)間",0,100);
}else if(i==1){
room[i][j] = new Room((i+1)*100+j+1,"單人間",0,75);
}else if(i==2){
room[i][j] = new Room((i+1)*100+j+1,"膠囊倉(cāng)",0,80);
}else if(i==3){
room[i][j] = new Room((i+1)*100+j+1,"總統(tǒng)套房",0,500);
}else if(i==4){
room[i][j] = new Room((i+1)*100+j+1,"夜景豪華套間",0,800);}
}
}
}
//打印所有房間信息
public void printroominfo()
{
System.out.println("房間狀態(tài)說(shuō)明:1:入?。?:空閑;-1:被預(yù)訂");
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();
}
}
//查詢房間狀態(tài)
public void printRoomstatus(int roomnumber)
{
if((room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
System.out.print(roomnumber +room[roomnumber/100-1][roomnumber%100-1].getType()+" 被預(yù)定" );
else if ((room[roomnumber/100-1][roomnumber%100-1].getStatus())==0)
System.out.print(roomnumber +room[roomnumber/100-1][roomnumber%100-1].getType()+" 空閑");
else if ((room[roomnumber/100-1][roomnumber%100-1].getStatus())==1)
System.out.print(roomnumber +room[roomnumber/100-1][roomnumber%100-1].getType()+" 已入住");
}
//預(yù)訂房間/取消預(yù)定
public void reserve(int ifOrnot,int roomnumber)
{ if (ifOrnot == 1)
{
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
{
System.out.println("預(yù)定失敗,該房間已被其他顧客預(yù)訂!");
}
else
{if((room[roomnumber/100-1][roomnumber%100-1].getStatus())==1)
{System.out.println("預(yù)定失敗,該房間已被入?。?);}
else
{
System.out.println("請(qǐng)輸入顧客的姓名:");
String customerName = sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setName(customerName);
System.out.println("請(qǐng)輸入顧客的年齡:");
int customerAge= sc.nextInt();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setAge(customerAge);
System.out.println("請(qǐng)輸入顧客的身份證號(hào):");
String customerId= sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setId(customerId);
System.out.println("請(qǐng)輸入顧客的電話號(hào)碼:");
String customerPhone= sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setPhone(customerPhone);
room[roomnumber/100-1][roomnumber%100-1].setStatus(-1);
System.out.println("預(yù)訂"+roomnumber+"成功!");}
}
}
else
{
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
{
room[roomnumber/100-1][roomnumber%100-1].setStatus(0);
System.out.println("取消預(yù)訂"+roomnumber+"成功!");
}
else
System.out.println("錯(cuò)誤!該房間已被使用或尚未預(yù)訂!詳情請(qǐng)查詢房間狀態(tài)。");
}
}
//入住酒店
public void checkIn(int reserveIf,int roomnumber)
{
if (reserveIf == 1)
{ room[roomnumber/100-1][roomnumber%100-1].setStatus(1);
Date startTime = new Date();
CheckList list = new CheckList(room[roomnumber/100-1][roomnumber%100-1],startTime);
checkList.add(list);
//初始價(jià)格賦值
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setPay(room[roomnumber/100-1][roomnumber%100-1].getPrice());
System.out.println("入住"+roomnumber+"成功!");
}
else
{
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
{
System.out.println("該房間已被其他顧客預(yù)訂!");
}
else
{if((room[roomnumber/100-1][roomnumber%100-1].getStatus())==1)
{System.out.println("該房間已被其他顧客入??!");}
else
{
System.out.println("請(qǐng)輸入顧客的姓名:");
String customerName = sc.next();
System.out.println("請(qǐng)輸入顧客的年齡:");
int customerAge= sc.nextInt();
System.out.println("請(qǐng)輸入顧客的身份證號(hào):");
String customerId= sc.next();
System.out.println("請(qǐng)輸入顧客的電話號(hào)碼:");
String customerPhone= sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.customer(customerName, customerAge, customerId, customerPhone);
room[roomnumber/100-1][roomnumber%100-1].setStatus(1);
//記錄入住信息
Date startTime = new Date();
CheckList list = new CheckList(room[roomnumber/100-1][roomnumber%100-1],startTime);
checkList.add(list);
//初始價(jià)格賦值
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setPay(room[roomnumber/100-1][roomnumber%100-1].getPrice());
System.out.println("入住"+roomnumber+"成功!");}
}
}
}
//退訂房間
public void checkOut(int roomnumber)
{
Date startTime = new Date();
Date endTime = new Date();
int j = 0;
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==0)
{
System.out.println("該房間已為空,請(qǐng)勿重復(fù)退訂");
}
else {
System.out.println("入住人:"+room[roomnumber/100-1][roomnumber%100-1].customerInfo.cname);
for( ;j < checkList.size();j++)
{
if(checkList.get(j).getRoom().getRoomnumber() == roomnumber)
{
startTime = checkList.get(j).getStartTime();
continue;
}
}
//計(jì)算費(fèi)用
int discount = discount(startTime,endTime);
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setPay(discount*room[roomnumber/100-1][roomnumber%100-1].customerInfo.getPay());
System.out.println("您的費(fèi)用為"+room[roomnumber/100-1][roomnumber%100-1].customerInfo.getPay());
//記錄
checkList.remove(j-1);
CheckOutList b = new CheckOutList(room[roomnumber/100-1][roomnumber%100-1],startTime,endTime);
historyList.add(b);
room[roomnumber/100-1][roomnumber%100-1].setStatus(1);
System.out.println("退訂"+roomnumber+"成功!");
}
}
//查看入住記錄
public void showCheckList()
{
if(checkList.size()!=0)
{
System.out.println("酒店的入住記錄如下:");
for(int i = 0;i < checkList.size();i++) {
System.out.println((i+1)+" 房間號(hào):"+checkList.get(i).getRoom().getRoomnumber()+" 類型:"+checkList.get(i).getRoom().getType()+" 入住旅客:"+checkList.get(i).getRoom().customerInfo.cname+
"身份證:"+checkList.get(i).getRoom().customerInfo.cid+" 入住入住"+ft.format(checkList.get(i).getStartTime()));
}
}
else
{
System.out.println("暫時(shí)還無(wú)入住記錄!");
}
}
//查看歷史記錄
public void showHistoryList()
{
if(historyList.size()!=0)
{
System.out.println("酒店的歷史記錄如下:");
for(int i = 0;i < historyList.size();i++) {
System.out.println((i+1)+" 房間號(hào):"+historyList.get(i).getRoom().getRoomnumber()+" 類型:"+historyList.get(i).getRoom().getType()+" 入住旅客:"+historyList.get(i).getRoom().customerInfo.cname+
"身份證:"+historyList.get(i).getRoom().customerInfo.cid+" 入住時(shí)間:"+ft.format(historyList.get(i).getStartTime())+" 離店時(shí)間:"+ft.format(historyList.get(i).getEndTime()));
}
}
else
{
System.out.println("暫時(shí)還無(wú)歷史記錄!");
}
}
//查看優(yōu)惠政策
public void printDiscount()
{
System.out.println("--------------優(yōu)惠政策-------------");
System.out.println("1.五一小長(zhǎng)假,國(guó)慶長(zhǎng)假期間入住打九折");
System.out.println("2.周年慶期間(7.10-7.15)住宿打八折");
System.out.println("3.清明,元旦傳統(tǒng)中國(guó)節(jié)日當(dāng)天入住打九折");
System.out.println("4.連續(xù)五天以上入住打九折");
System.out.println("5.以上折扣不疊加,以最大折扣值為準(zhǔn)");
}
//查詢旅客信息
public void checkCustomerInfo()
{
System.out.println("請(qǐng)輸入旅客姓名:");
int i,j = 0;
String name = sc.next();
for(i = 0; i< room.length; i++)
{
for(j = 0;j< room.length; j++)
{
if(name.equals(room[i][j].customerInfo.cname)){
System.out.println("姓名 \t 年齡 \t 電話 \t 身份證號(hào) \t 房間類型 \t 收費(fèi)");
System.out.println( room[i][j].customerInfo.cname + "\t" + room[i][j].customerInfo.age + "\t" + room[i][j].customerInfo.phone + "\t" + room[i][j].customerInfo.cid + "\t\t\t" + room[i][j].type + "\t" + room[i][j].customerInfo.pay);
System.out.println("***查詢完成!***");
}
}
}
if(i == room.length){
System.out.println("不存在其旅客!");
}
}
//優(yōu)惠函數(shù)
@SuppressWarnings("deprecation")
public int discount(Date startTime,Date endTime) {
long day = (endTime.getTime()-startTime.getTime())/(1000 * 60 * 60 * 24);
int month1 = startTime.getMonth();
int day1 = startTime.getDay();
if (startTime.getDay() == endTime.getDay() || startTime.getMonth()== endTime.getMonth())
{ day = 1;}
if(month1 == 7 && day1 >= 10 &&day1 <= 15)
{
return (int) (day*0.8);
}
else if((month1 == 10 && day1 >= 1 &&day1 <= 7)||(month1 == 5 && day1 >= 1 &&day1 <= 7)||(month1 == 4 && day1 == 1 )||(month1 == 1 && day1 == 1 ))
{
return (int) (day*0.9);
}
else if(day >= 5)
{
return (int) (day*0.9);
}
else
return (int)day;
}
}
HotelSystem
菜單即前臺(tái)系統(tǒng)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-512955.html
import java.util.*;
public class HotelSystem
{
public static Scanner sc = new Scanner(System.in);
public static void menu()
{
System.out.println("歡迎使用酒店前臺(tái)管理系統(tǒng)!");
System.out.println("1.查看所有房間信息");
System.out.println("2.查詢房間狀態(tài)");
System.out.println("3.預(yù)訂房間/取消預(yù)定");
System.out.println("4.辦理入住");
System.out.println("5.結(jié)算賬單,退訂房間");
System.out.println("6.查詢?nèi)胱∮涗?);
System.out.println("7.查詢歷史記錄");
System.out.println("8.查詢折扣政策");
System.out.println("9.查詢旅客信息");
System.out.println("0.退出系統(tǒng)");
System.out.println("請(qǐng)輸入:");
}
public static void main(String[] args)
{
Hotel hotel = new Hotel();
int number = -1;
do {
menu();
int choice = sc.nextInt();
if (choice == 0)
{
number=choice;
System.out.println("您已成功退出系統(tǒng)!");
continue;
}
switch (choice)
{
case 1:
hotel.printroominfo();
break;
case 2:
System.out.println("輸入想要查詢的房間號(hào):");
int roomnumber2 = sc.nextInt();
hotel.printRoomstatus(roomnumber2);
break;
case 3:
System.out.println("取消預(yù)定or預(yù)定房間?1.預(yù)定房間 2.取消預(yù)定");
int ifOrnot = sc.nextInt();
System.out.println("輸入房間號(hào):");
int roomnumber3 = sc.nextInt();
hotel.reserve(ifOrnot,roomnumber3);
break;
case 4:
System.out.println("是否具有預(yù)訂?1.是 2.否");
int reserveIf = sc.nextInt();
System.out.println("輸入房間號(hào):");
int roomnumber4 = sc.nextInt();
hotel.checkIn(reserveIf,roomnumber4);
break;
case 5:
System.out.println("輸入房間號(hào):");
int roomnumber5 = sc.nextInt();
hotel.checkOut(roomnumber5);
break;
case 6:
hotel.showCheckList();
break;
case 7:
hotel.showHistoryList();
break;
case 8:
hotel.printDiscount();
break;
case 9:
hotel.checkCustomerInfo();
break;
default:
System.out.println("輸入錯(cuò)誤,請(qǐng)重新輸入!");
break;
}
} while(number != 0);
sc.close();
}
}
最近比較忙,后續(xù)再將反思發(fā)出來(lái)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-512955.html
到了這里,關(guān)于酒店管理系統(tǒng)(Java實(shí)現(xiàn))的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!