酒店管理系统java实现
时间: 2023-07-31 16:04:55 浏览: 52
酒店管理系统是一种常见的管理信息系统,它可以帮助酒店管理者进行酒店的日常运营管理。下面是一个简单的酒店管理系统java实现的示例:
1. 酒店房间类Room.java
```
public class Room {
private int roomId;
private String roomType;
private String roomStatus;
private double roomPrice;
public Room(int roomId, String roomType, String roomStatus, double roomPrice) {
this.roomId = roomId;
this.roomType = roomType;
this.roomStatus = roomStatus;
this.roomPrice = roomPrice;
}
public int getRoomId() {
return roomId;
}
public void setRoomId(int roomId) {
this.roomId = roomId;
}
public String getRoomType() {
return roomType;
}
public void setRoomType(String roomType) {
this.roomType = roomType;
}
public String getRoomStatus() {
return roomStatus;
}
public void setRoomStatus(String roomStatus) {
this.roomStatus = roomStatus;
}
public double getRoomPrice() {
return roomPrice;
}
public void setRoomPrice(double roomPrice) {
this.roomPrice = roomPrice;
}
}
```
2. 酒店管理类Hotel.java
```
import java.util.ArrayList;
import java.util.List;
public class Hotel {
private List<Room> rooms = new ArrayList<>();
public void addRoom(Room room) {
rooms.add(room);
}
public void removeRoom(Room room) {
rooms.remove(room);
}
public List<Room> getRooms() {
return rooms;
}
public List<Room> getAvailableRooms() {
List<Room> availableRooms = new ArrayList<>();
for (Room room : rooms) {
if (room.getRoomStatus().equals("available")) {
availableRooms.add(room);
}
}
return availableRooms;
}
public List<Room> getOccupiedRooms() {
List<Room> occupiedRooms = new ArrayList<>();
for (Room room : rooms) {
if (room.getRoomStatus().equals("occupied")) {
occupiedRooms.add(room);
}
}
return occupiedRooms;
}
public List<Room> getRoomsByType(String roomType) {
List<Room> roomsByType = new ArrayList<>();
for (Room room : rooms) {
if (room.getRoomType().equals(roomType)) {
roomsByType.add(room);
}
}
return roomsByType;
}
public double getOccupancyRate() {
int totalRooms = rooms.size();
int occupiedRooms = getOccupiedRooms().size();
return (double)occupiedRooms / totalRooms;
}
public double getAverageRoomPrice() {
double totalRoomPrice = 0;
for (Room room : rooms) {
totalRoomPrice += room.getRoomPrice();
}
return totalRoomPrice / rooms.size();
}
}
```
3. 酒店管理系统主程序HotelManagementSystem.java
```
import java.util.List;
import java.util.Scanner;
public class HotelManagementSystem {
public static void main(String[] args) {
Hotel hotel = new Hotel();
// 添加房间
Room room1 = new Room(101, "single", "available", 100);
Room room2 = new Room(102, "double", "available", 200);
Room room3 = new Room(103, "single", "occupied", 100);
hotel.addRoom(room1);
hotel.addRoom(room2);
hotel.addRoom(room3);
Scanner scanner = new Scanner(System.in);
while (true) {
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. 退出系统");
String option = scanner.next();
switch (option) {
case "1":
List<Room> rooms = hotel.getRooms();
System.out.println("所有房间信息:");
for (Room room : rooms) {
System.out.println(room.getRoomId() + " " + room.getRoomType() + " " + room.getRoomStatus() + " " + room.getRoomPrice());
}
break;
case "2":
List<Room> availableRooms = hotel.getAvailableRooms();
System.out.println("空闲房间信息:");
for (Room room : availableRooms) {
System.out.println(room.getRoomId() + " " + room.getRoomType() + " " + room.getRoomStatus() + " " + room.getRoomPrice());
}
break;
case "3":
List<Room> occupiedRooms = hotel.getOccupiedRooms();
System.out.println("已入住房间信息:");
for (Room room : occupiedRooms) {
System.out.println(room.getRoomId() + " " + room.getRoomType() + " " + room.getRoomStatus() + " " + room.getRoomPrice());
}
break;
case "4":
System.out.println("请输入房间类型:");
String roomType = scanner.next();
List<Room> roomsByType = hotel.getRoomsByType(roomType);
System.out.println("指定类型房间信息:");
for (Room room : roomsByType) {
System.out.println(room.getRoomId() + " " + room.getRoomType() + " " + room.getRoomStatus() + " " + room.getRoomPrice());
}
break;
case "5":
double occupancyRate = hotel.getOccupancyRate();
System.out.println("酒店入住率:" + occupancyRate);
break;
case "6":
double averageRoomPrice = hotel.getAverageRoomPrice();
System.out.println("酒店平均房价:" + averageRoomPrice);
break;
case "7":
System.exit(0);
break;
default:
System.out.println("无效操作,请重新选择!");
break;
}
}
}
}
```
以上是一个简单的酒店管理系统java实现的示例,可以根据实际需要进一步扩展和完善。
阅读全文