Java课程作业,酒店管理系统由前台系统实现主要功能,具备以下功能:
目录
Room
Customer
CheckList
Hotel
HotelSystem
Room
Room类,包含了房间号,房间类型,房间状态(住宿还是空闲),房间价格,以及入住人信息。
//Room 类
import java.util.Objects;
public class Room{
private int roomnumber;
public String type;
private int status;//房间状态,1:入住;0:空闲;-1:被预订
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方法,可以转换成输出房间信息
@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+","+"已预订"+"}";
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类,用于实现顾客属性。
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
这个是老师让改的一部分,对于查询记录的类
//记录类
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
主要功能酒店类,实现以上菜单内的所有功能
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,"标准间",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,"胶囊仓",0,80);
}else if(i==3){
room[i][j] = new Room((i+1)*100+j+1,"总统套房",0,500);
}else if(i==4){
room[i][j] = new Room((i+1)*100+j+1,"夜景豪华套间",0,800);}
}
}
}
//打印所有房间信息
public void printroominfo()
{
System.out.println("房间状态说明:1:入住;0:空闲;-1:被预订");
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 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()+" 被预定" );
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()+" 已入住");
}
//预订房间/取消预定
public void reserve(int ifOrnot,int roomnumber)
{ if (ifOrnot == 1)
{
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
{
System.out.println("预定失败,该房间已被其他顾客预订!");
}
else
{if((room[roomnumber/100-1][roomnumber%100-1].getStatus())==1)
{System.out.println("预定失败,该房间已被入住!");}
else
{
System.out.println("请输入顾客的姓名:");
String customerName = sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setName(customerName);
System.out.println("请输入顾客的年龄:");
int customerAge= sc.nextInt();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setAge(customerAge);
System.out.println("请输入顾客的身份证号:");
String customerId= sc.next();
room[roomnumber/100-1][roomnumber%100-1].customerInfo.setId(customerId);
System.out.println("请输入顾客的电话号码:");
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("预订"+roomnumber+"成功!");}
}
}
else
{
if( (room[roomnumber/100-1][roomnumber%100-1].getStatus())==-1)
{
room[roomnumber/100-1][roomnumber%100-1].setStatus(0);
System.out.println("取消预订"+roomnumber+"成功!");
}
else
System.out.println("错误!该房间已被使用或尚未预订!详情请查询房间状态。");
}
}
//入住酒店
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);
//初始价格赋值
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("该房间已被其他顾客预订!");
}
else
{if((room[roomnumber/100-1][roomnumber%100-1].getStatus())==1)
{System.out.println("该房间已被其他顾客入住!");}
else
{
System.out.println("请输入顾客的姓名:");
String customerName = sc.next();
System.out.println("请输入顾客的年龄:");
int customerAge= sc.nextInt();
System.out.println("请输入顾客的身份证号:");
String customerId= sc.next();
System.out.println("请输入顾客的电话号码:");
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);
//初始价格赋值
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("该房间已为空,请勿重复退订");
}
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;
}
}
//计算费用
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("您的费用为"+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)+" 房间号:"+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("暂时还无入住记录!");
}
}
//查看历史记录
public void showHistoryList()
{
if(historyList.size()!=0)
{
System.out.println("酒店的历史记录如下:");
for(int i = 0;i < historyList.size();i++) {
System.out.println((i+1)+" 房间号:"+historyList.get(i).getRoom().getRoomnumber()+" 类型:"+historyList.get(i).getRoom().getType()+" 入住旅客:"+historyList.get(i).getRoom().customerInfo.cname+
"身份证:"+historyList.get(i).getRoom().customerInfo.cid+" 入住时间:"+ft.format(historyList.get(i).getStartTime())+" 离店时间:"+ft.format(historyList.get(i).getEndTime()));
}
}
else
{
System.out.println("暂时还无历史记录!");
}
}
//查看优惠政策
public void printDiscount()
{
System.out.println("--------------优惠政策-------------");
System.out.println("1.五一小长假,国庆长假期间入住打九折");
System.out.println("2.周年庆期间(7.10-7.15)住宿打八折");
System.out.println("3.清明,元旦传统中国节日当天入住打九折");
System.out.println("4.连续五天以上入住打九折");
System.out.println("5.以上折扣不叠加,以最大折扣值为准");
}
//查询旅客信息
public void checkCustomerInfo()
{
System.out.println("请输入旅客姓名:");
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 身份证号 \t 房间类型 \t 收费");
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("不存在其旅客!");
}
}
//优惠函数
@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
菜单即前台系统文章来源:https://www.toymoban.com/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("欢迎使用酒店前台管理系统!");
System.out.println("1.查看所有房间信息");
System.out.println("2.查询房间状态");
System.out.println("3.预订房间/取消预定");
System.out.println("4.办理入住");
System.out.println("5.结算账单,退订房间");
System.out.println("6.查询入住记录");
System.out.println("7.查询历史记录");
System.out.println("8.查询折扣政策");
System.out.println("9.查询旅客信息");
System.out.println("0.退出系统");
System.out.println("请输入:");
}
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("您已成功退出系统!");
continue;
}
switch (choice)
{
case 1:
hotel.printroominfo();
break;
case 2:
System.out.println("输入想要查询的房间号:");
int roomnumber2 = sc.nextInt();
hotel.printRoomstatus(roomnumber2);
break;
case 3:
System.out.println("取消预定or预定房间?1.预定房间 2.取消预定");
int ifOrnot = sc.nextInt();
System.out.println("输入房间号:");
int roomnumber3 = sc.nextInt();
hotel.reserve(ifOrnot,roomnumber3);
break;
case 4:
System.out.println("是否具有预订?1.是 2.否");
int reserveIf = sc.nextInt();
System.out.println("输入房间号:");
int roomnumber4 = sc.nextInt();
hotel.checkIn(reserveIf,roomnumber4);
break;
case 5:
System.out.println("输入房间号:");
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("输入错误,请重新输入!");
break;
}
} while(number != 0);
sc.close();
}
}
最近比较忙,后续再将反思发出来。文章来源地址https://www.toymoban.com/news/detail-512955.html
到了这里,关于酒店管理系统(Java实现)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!