用JAVA写一个酒店管理系统
时间: 2023-12-29 22:17:43 浏览: 39
好的,酒店管理系统可以分为客房管理、顾客管理、订单管理三个部分,下面我来简单介绍一下如何用JAVA实现一个酒店管理系统。
1.客房管理
客房管理主要包括客房信息的录入、查询、修改和删除,以下是部分代码示例:
```
public class Room {
private int id; //客房编号
private String type; //客房类型
private String status; //客房状态
//构造方法
public Room(int id, String type, String status) {
this.id = id;
this.type = type;
this.status = status;
}
//getter和setter方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
public class RoomManage {
private List<Room> roomList; //客房列表
//构造方法
public RoomManage() {
roomList = new ArrayList<>();
}
//添加客房
public void addRoom(Room room) {
roomList.add(room);
}
//查询客房
public Room findRoom(int id) {
for (Room room : roomList) {
if (room.getId() == id) {
return room;
}
}
return null;
}
//修改客房
public void updateRoom(Room room) {
Room oldRoom = findRoom(room.getId());
oldRoom.setType(room.getType());
oldRoom.setStatus(room.getStatus());
}
//删除客房
public void deleteRoom(int id) {
Room room = findRoom(id);
roomList.remove(room);
}
}
```
2.顾客管理
顾客管理主要包括顾客信息的录入、查询、修改和删除,以下是部分代码示例:
```
public class Customer {
private int id; //顾客编号
private String name; //顾客姓名
private String phone; //顾客电话
//构造方法
public Customer(int id, String name, String phone) {
this.id = id;
this.name = name;
this.phone = phone;
}
//getter和setter方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
public class CustomerManage {
private List<Customer> customerList; //顾客列表
//构造方法
public CustomerManage() {
customerList = new ArrayList<>();
}
//添加顾客
public void addCustomer(Customer customer) {
customerList.add(customer);
}
//查询顾客
public Customer findCustomer(int id) {
for (Customer customer : customerList) {
if (customer.getId() == id) {
return customer;
}
}
return null;
}
//修改顾客
public void updateCustomer(Customer customer) {
Customer oldCustomer = findCustomer(customer.getId());
oldCustomer.setName(customer.getName());
oldCustomer.setPhone(customer.getPhone());
}
//删除顾客
public void deleteCustomer(int id) {
Customer customer = findCustomer(id);
customerList.remove(customer);
}
}
```
3.订单管理
订单管理主要包括订单的录入、查询、修改和删除,以下是部分代码示例:
```
public class Order {
private int id; //订单编号
private int roomId; //客房编号
private int customerId; //顾客编号
private String checkInDate; //入住日期
private String checkOutDate; //退房日期
private int price; //订单价格
//构造方法
public Order(int id, int roomId, int customerId, String checkInDate, String checkOutDate, int price) {
this.id = id;
this.roomId = roomId;
this.customerId = customerId;
this.checkInDate = checkInDate;
this.checkOutDate = checkOutDate;
this.price = price;
}
//getter和setter方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getRoomId() {
return roomId;
}
public void setRoomId(int roomId) {
this.roomId = roomId;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCheckInDate() {
return checkInDate;
}
public void setCheckInDate(String checkInDate) {
this.checkInDate = checkInDate;
}
public String getCheckOutDate() {
return checkOutDate;
}
public void setCheckOutDate(String checkOutDate) {
this.checkOutDate = checkOutDate;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
public class OrderManage {
private List<Order> orderList; //订单列表
//构造方法
public OrderManage() {
orderList = new ArrayList<>();
}
//添加订单
public void addOrder(Order order) {
orderList.add(order);
}
//查询订单
public Order findOrder(int id) {
for (Order order : orderList) {
if (order.getId() == id) {
return order;
}
}
return null;
}
//修改订单
public void updateOrder(Order order) {
Order oldOrder = findOrder(order.getId());
oldOrder.setRoomId(order.getRoomId());
oldOrder.setCustomerId(order.getCustomerId());
oldOrder.setCheckInDate(order.getCheckInDate());
oldOrder.setCheckOutDate(order.getCheckOutDate());
oldOrder.setPrice(order.getPrice());
}
//删除订单
public void deleteOrder(int id) {
Order order = findOrder(id);
orderList.remove(order);
}
}
```
以上是酒店管理系统的核心代码,你可以根据自己的需要进行修改和完善。
阅读全文