用java写一个餐饮信息管理系统
时间: 2023-07-18 14:36:33 浏览: 102
好的,我可以为您提供一个基本的餐饮信息管理系统的Java代码框架,具体功能包括添加、删除、修改和查找餐厅信息、餐厅菜单和订单信息等。以下是代码框架:
```java
import java.util.*;
public class Restaurant {
private String name;
private String address;
private String phone;
private Map<String, Double> menu; // 餐厅菜单
public Restaurant(String name, String address, String phone) {
this.name = name;
this.address = address;
this.phone = phone;
menu = new HashMap<>();
}
// 添加菜品到菜单
public void addDish(String dishName, double price) {
menu.put(dishName, price);
}
// 删除菜品
public void removeDish(String dishName) {
menu.remove(dishName);
}
// 修改菜品价格
public void modifyPrice(String dishName, double newPrice) {
menu.replace(dishName, newPrice);
}
// 搜索菜品
public Double searchDish(String dishName) {
return menu.get(dishName);
}
// 输出菜单
public void printMenu() {
System.out.println("菜单:");
for (String dishName : menu.keySet()) {
System.out.println(dishName + "\t" + menu.get(dishName));
}
}
}
public class Order {
private Restaurant restaurant;
private List<String> dishes; // 订单菜单
public Order(Restaurant restaurant) {
this.restaurant = restaurant;
dishes = new ArrayList<>();
}
// 添加菜品到订单
public void addDish(String dishName) {
dishes.add(dishName);
}
// 删除订单中的菜品
public void removeDish(String dishName) {
dishes.remove(dishName);
}
// 计算订单价格
public double calculatePrice() {
double totalPrice = 0;
for (String dishName : dishes) {
Double price = restaurant.searchDish(dishName);
if (price != null) {
totalPrice += price;
}
}
return totalPrice;
}
// 输出订单详情
public void printOrder() {
System.out.println("订单详情:");
for (String dishName : dishes) {
System.out.println(dishName + "\t" + restaurant.searchDish(dishName));
}
System.out.println("总价:" + calculatePrice());
}
}
public class RestaurantManagementSystem {
private List<Restaurant> restaurants; // 餐厅列表
public RestaurantManagementSystem() {
restaurants = new ArrayList<>();
}
// 添加餐厅
public void addRestaurant(Restaurant restaurant) {
restaurants.add(restaurant);
}
// 删除餐厅
public void removeRestaurant(Restaurant restaurant) {
restaurants.remove(restaurant);
}
// 搜索餐厅
public Restaurant searchRestaurant(String restaurantName) {
for (Restaurant restaurant : restaurants) {
if (restaurant.getName().equals(restaurantName)) {
return restaurant;
}
}
return null;
}
// 输出所有餐厅信息
public void printRestaurants() {
System.out.println("餐厅列表:");
for (Restaurant restaurant : restaurants) {
System.out.println(restaurant.getName() + "\t" + restaurant.getAddress() + "\t" + restaurant.getPhone());
}
}
public static void main(String[] args) {
// 初始化餐厅信息
Restaurant restaurant1 = new Restaurant("餐厅1", "地址1", "电话1");
restaurant1.addDish("菜品1", 10.0);
restaurant1.addDish("菜品2", 20.0);
Restaurant restaurant2 = new Restaurant("餐厅2", "地址2", "电话2");
restaurant2.addDish("菜品3", 30.0);
restaurant2.addDish("菜品4", 40.0);
// 初始化订单信息
Order order1 = new Order(restaurant1);
order1.addDish("菜品1");
order1.addDish("菜品2");
Order order2 = new Order(restaurant2);
order2.addDish("菜品3");
order2.addDish("菜品4");
// 输出餐厅和订单信息
RestaurantManagementSystem rm = new RestaurantManagementSystem();
rm.addRestaurant(restaurant1);
rm.addRestaurant(restaurant2);
rm.printRestaurants();
System.out.println();
order1.printOrder();
order2.printOrder();
}
}
```
该代码框架实现了基本的餐饮信息管理系统,您可以根据自己的需求进行修改和扩展。需要注意的是,该代码框架仅为参考,实际应用中还需要考虑更多的情况和细节。
阅读全文