帮我用java写一个餐饮管理系统
时间: 2023-06-27 17:07:36 浏览: 201
餐饮管理系统(用java编写,供毕设和学习用)
4星 · 用户满意度95%
好的,餐饮管理系统可以包括以下功能:
1. 菜单管理:可以添加、修改、删除菜品,以及菜品分类管理;
2. 订单管理:记录所有订单信息,包括下单时间、顾客信息、菜品信息、订单状态等;
3. 库存管理:记录所有原材料的进出库情况,以及菜品所需原材料的库存情况;
4. 会员管理:记录顾客的会员信息,包括会员等级、积分等;
5. 报表统计:根据时间、菜品、顾客等维度进行统计分析,生成营业额、热销菜品、顾客偏好等报表。
以下是一个简单的 Java 实现:
```java
import java.util.*;
class MenuItem {
private String name;
private double price;
private String category;
public MenuItem(String name, double price, String category) {
this.name = name;
this.price = price;
this.category = category;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public String getCategory() {
return category;
}
}
class Order {
private int id;
private Date date;
private List<MenuItem> items;
private String status;
private String customerName;
private String customerPhone;
public Order(int id, Date date, List<MenuItem> items, String status, String customerName, String customerPhone) {
this.id = id;
this.date = date;
this.items = items;
this.status = status;
this.customerName = customerName;
this.customerPhone = customerPhone;
}
public int getId() {
return id;
}
public Date getDate() {
return date;
}
public List<MenuItem> getItems() {
return items;
}
public String getStatus() {
return status;
}
public String getCustomerName() {
return customerName;
}
public String getCustomerPhone() {
return customerPhone;
}
}
class Stock {
private Map<String, Integer> ingredients;
public Stock(Map<String, Integer> ingredients) {
this.ingredients = ingredients;
}
public void addIngredient(String name, int quantity) {
if (ingredients.containsKey(name)) {
ingredients.put(name, ingredients.get(name) + quantity);
} else {
ingredients.put(name, quantity);
}
}
public void removeIngredient(String name, int quantity) {
if (ingredients.containsKey(name)) {
int remaining = ingredients.get(name) - quantity;
if (remaining >= 0) {
ingredients.put(name, remaining);
} else {
throw new RuntimeException("Insufficient stock");
}
} else {
throw new RuntimeException("Ingredient not found");
}
}
public int getIngredientQuantity(String name) {
if (ingredients.containsKey(name)) {
return ingredients.get(name);
} else {
throw new RuntimeException("Ingredient not found");
}
}
}
class Member {
private String name;
private String phone;
private int level;
private int points;
public Member(String name, String phone, int level, int points) {
this.name = name;
this.phone = phone;
this.level = level;
this.points = points;
}
public String getName() {
return name;
}
public String getPhone() {
return phone;
}
public int getLevel() {
return level;
}
public int getPoints() {
return points;
}
public void addPoints(int amount) {
points += amount;
}
}
class Report {
public static double calculateRevenue(List<Order> orders, Date startDate, Date endDate) {
double revenue = 0.0;
for (Order order : orders) {
if (order.getDate().after(startDate) && order.getDate().before(endDate)) {
for (MenuItem item : order.getItems()) {
revenue += item.getPrice();
}
}
}
return revenue;
}
public static Map<String, Integer> calculateQuantityByCategory(List<Order> orders, Date startDate, Date endDate) {
Map<String, Integer> quantityByCategory = new HashMap<>();
for (Order order : orders) {
if (order.getDate().after(startDate) && order.getDate().before(endDate)) {
for (MenuItem item : order.getItems()) {
String category = item.getCategory();
if (quantityByCategory.containsKey(category)) {
quantityByCategory.put(category, quantityByCategory.get(category) + 1);
} else {
quantityByCategory.put(category, 1);
}
}
}
}
return quantityByCategory;
}
public static Map<String, Integer> calculateQuantityByCustomer(List<Order> orders, Date startDate, Date endDate) {
Map<String, Integer> quantityByCustomer = new HashMap<>();
for (Order order : orders) {
if (order.getDate().after(startDate) && order.getDate().before(endDate)) {
String customerName = order.getCustomerName();
if (quantityByCustomer.containsKey(customerName)) {
quantityByCustomer.put(customerName, quantityByCustomer.get(customerName) + 1);
} else {
quantityByCustomer.put(customerName, 1);
}
}
}
return quantityByCustomer;
}
}
class Restaurant {
private List<MenuItem> menu;
private List<Order> orders;
private Stock stock;
private List<Member> members;
public Restaurant(List<MenuItem> menu, Stock stock) {
this.menu = menu;
this.orders = new ArrayList<>();
this.stock = stock;
this.members = new ArrayList<>();
}
public void addMenuItem(MenuItem item) {
menu.add(item);
}
public void removeMenuItem(String name) {
menu.removeIf(item -> item.getName().equals(name));
}
public void placeOrder(Order order) {
for (MenuItem item : order.getItems()) {
String ingredient = item.getName();
int quantity = 1;
stock.removeIngredient(ingredient, quantity);
}
orders.add(order);
}
public void addMember(Member member) {
members.add(member);
}
public void removeMember(String phone) {
members.removeIf(member -> member.getPhone().equals(phone));
}
public List<MenuItem> getMenu() {
return menu;
}
public List<Order> getOrders() {
return orders;
}
public Stock getStock() {
return stock;
}
public List<Member> getMembers() {
return members;
}
}
public class Main {
public static void main(String[] args) {
// create menu
List<MenuItem> menu = new ArrayList<>();
menu.add(new MenuItem("Hamburger", 8.0, "Fast Food"));
menu.add(new MenuItem("Pizza", 10.0, "Fast Food"));
menu.add(new MenuItem("Steak", 20.0, "Main Course"));
menu.add(new MenuItem("Salad", 6.0, "Appetizer"));
// create stock
Map<String, Integer> ingredients = new HashMap<>();
ingredients.put("Beef", 50);
ingredients.put("Bread", 100);
ingredients.put("Cheese", 20);
ingredients.put("Tomato", 30);
Stock stock = new Stock(ingredients);
// create restaurant
Restaurant restaurant = new Restaurant(menu, stock);
// create orders
List<Order> orders = new ArrayList<>();
orders.add(new Order(1, new Date(), Arrays.asList(menu.get(0), menu.get(3)), "Pending", "John Smith", "1234567890"));
orders.add(new Order(2, new Date(), Arrays.asList(menu.get(1), menu.get(2)), "Completed", "Jane Doe", "0987654321"));
// add members
List<Member> members = new ArrayList<>();
members.add(new Member("Tom Lee", "1111111111", 1, 100));
members.add(new Member("Mary Wong", "2222222222", 2, 200));
members.add(new Member("Jack Chan", "3333333333", 3, 300));
// add menu items, place orders, and add members to the restaurant
for (MenuItem item : menu) {
restaurant.addMenuItem(item);
}
for (Order order : orders) {
restaurant.placeOrder(order);
}
for (Member member : members) {
restaurant.addMember(member);
}
// generate reports
Date startDate = new Date(2021, 1, 1);
Date endDate = new Date();
double revenue = Report.calculateRevenue(orders, startDate, endDate);
Map<String, Integer> quantityByCategory = Report.calculateQuantityByCategory(orders, startDate, endDate);
Map<String, Integer> quantityByCustomer = Report.calculateQuantityByCustomer(orders, startDate, endDate);
// print reports
System.out.println("Revenue: " + revenue);
System.out.println("Quantity by category: " + quantityByCategory);
System.out.println("Quantity by customer: " + quantityByCustomer);
}
}
```
注意,这只是一个简单的实现,仅供参考。具体的需求和业务流程可能因餐厅的不同而有所不同,需要根据实际情况进行调整。
阅读全文