简易的java酒店管理系统
时间: 2023-10-15 18:02:43 浏览: 74
酒店管理系统_java_酒店管理系统_
5星 · 资源好评率100%
好的,下面是一个简易的Java酒店管理系统,包括客房管理、预订、入住和退房等功能:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class HotelManagementSystem {
private static ArrayList<Room> roomList = new ArrayList<>();
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// 初始化房间信息
for (int i = 1; i <= 10; i++) {
roomList.add(new Room(i, "单人间", "空闲"));
}
for (int i = 11; i <= 20; i++) {
roomList.add(new Room(i, "双人间", "空闲"));
}
while (true) {
System.out.println();
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.print("请选择操作:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
printRoomList();
break;
case 2:
reserveRoom();
break;
case 3:
checkinRoom();
break;
case 4:
checkoutRoom();
break;
case 5:
System.out.println("谢谢使用酒店管理系统!");
System.exit(0);
default:
System.out.println("无效操作,请重新选择!");
break;
}
}
}
// 打印客房列表
private static void printRoomList() {
System.out.println("客房列表:");
for (Room room : roomList) {
System.out.println(room);
}
}
// 预订客房
private static void reserveRoom() {
System.out.print("请输入要预订的客房号码:");
int roomId = scanner.nextInt();
Room room = findRoom(roomId);
if (room == null) {
System.out.println("客房不存在!");
} else if (room.getStatus().equals("预订") || room.getStatus().equals("入住")) {
System.out.println("客房已被预订或入住!");
} else {
System.out.print("请输入预订人姓名:");
String name = scanner.next();
System.out.print("请输入预订日期:");
String date = scanner.next();
room.setReserve(name, date);
System.out.println("预订成功!");
}
}
// 入住客房
private static void checkinRoom() {
System.out.print("请输入要入住的客房号码:");
int roomId = scanner.nextInt();
Room room = findRoom(roomId);
if (room == null) {
System.out.println("客房不存在!");
} else if (room.getStatus().equals("预订") || room.getStatus().equals("入住")) {
System.out.println("客房已被预订或入住!");
} else {
System.out.print("请输入入住人姓名:");
String name = scanner.next();
System.out.print("请输入入住日期:");
String date = scanner.next();
room.setCheckin(name, date);
System.out.println("入住成功!");
}
}
// 退房
private static void checkoutRoom() {
System.out.print("请输入要退房的客房号码:");
int roomId = scanner.nextInt();
Room room = findRoom(roomId);
if (room == null) {
System.out.println("客房不存在!");
} else if (room.getStatus().equals("空闲")) {
System.out.println("客房未被预订或入住!");
} else {
System.out.print("请输入退房日期:");
String date = scanner.next();
room.setCheckout(date);
System.out.println("退房成功!");
}
}
// 根据房间号码查找房间
private static Room findRoom(int roomId) {
for (Room room : roomList) {
if (room.getId() == roomId) {
return room;
}
}
return null;
}
}
class Room {
private int id;
private String type;
private String status;
private String reserveName;
private String reserveDate;
private String checkinName;
private String checkinDate;
private String checkoutDate;
public Room(int id, String type, String status) {
this.id = id;
this.type = type;
this.status = status;
}
public int getId() {
return id;
}
public String getType() {
return type;
}
public String getStatus() {
return status;
}
public String getReserveName() {
return reserveName;
}
public String getReserveDate() {
return reserveDate;
}
public String getCheckinName() {
return checkinName;
}
public String getCheckinDate() {
return checkinDate;
}
public String getCheckoutDate() {
return checkoutDate;
}
// 设置预订信息
public void setReserve(String name, String date) {
reserveName = name;
reserveDate = date;
status = "预订";
}
// 设置入住信息
public void setCheckin(String name, String date) {
checkinName = name;
checkinDate = date;
status = "入住";
}
// 设置退房信息
public void setCheckout(String date) {
checkoutDate = date;
reserveName = "";
reserveDate = "";
checkinName = "";
checkinDate = "";
status = "空闲";
}
@Override
public String toString() {
String str = "客房号码:" + id + ",类型:" + type + ",状态:" + status;
if (status.equals("预订")) {
str += ",预订人:" + reserveName + ",预订日期:" + reserveDate;
} else if (status.equals("入住")) {
str += ",入住人:" + checkinName + ",入住日期:" + checkinDate;
} else if (status.equals("退房")) {
str += ",退房日期:" + checkoutDate;
}
return str;
}
}
```
这个系统使用了一个Room类来表示客房,包含了客房号码、客房类型、客房状态(空闲、预订或入住)以及客人的预订、入住和退房信息。HotelManagementSystem类则提供了一系列方法来实现客房管理、预订、入住和退房等功能。
阅读全文