写一个Java程序关于咖啡馆管理的
时间: 2023-09-27 08:11:57 浏览: 111
好的,我可以给你提供一个简单的Java程序框架,用于咖啡馆管理。这个框架包括了一些常见的咖啡馆业务流程,比如点餐、结账等。你可以在此基础上进行修改和扩展,实现你自己的咖啡馆管理系统。
```
import java.util.ArrayList;
import java.util.Scanner;
public class CafeManager {
private ArrayList<Coffee> coffeeMenu; // 咖啡菜单
private ArrayList<Order> orderList; // 订单列表
private double totalIncome; // 总收入
public CafeManager() {
coffeeMenu = new ArrayList<Coffee>();
orderList = new ArrayList<Order>();
totalIncome = 0;
}
// 初始化咖啡菜单
public void initMenu() {
coffeeMenu.add(new Coffee("拿铁", 20));
coffeeMenu.add(new Coffee("卡布奇诺", 25));
coffeeMenu.add(new Coffee("美式咖啡", 18));
coffeeMenu.add(new Coffee("摩卡", 28));
}
// 显示咖啡菜单
public void showMenu() {
System.out.println("咖啡菜单:");
for (Coffee coffee : coffeeMenu) {
System.out.println(coffee.getName() + " " + coffee.getPrice() + "元");
}
}
// 点餐
public void placeOrder() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入您要点的咖啡名称:");
String coffeeName = scanner.nextLine();
System.out.println("请输入您要点的数量:");
int amount = scanner.nextInt();
// 查找咖啡
Coffee coffee = null;
for (Coffee c : coffeeMenu) {
if (c.getName().equals(coffeeName)) {
coffee = c;
break;
}
}
// 如果找不到咖啡,报错
if (coffee == null) {
System.out.println("找不到该咖啡,请重新输入!");
return;
}
// 创建订单
Order order = new Order(coffee, amount);
orderList.add(order);
System.out.println("成功下单:" + order.getCoffee().getName() + " " + order.getAmount() + "杯");
}
// 结账
public void checkout() {
System.out.println("订单列表:");
for (Order order : orderList) {
System.out.println(order.getCoffee().getName() + " " + order.getAmount() + "杯 " + order.getTotalPrice() + "元");
totalIncome += order.getTotalPrice();
}
System.out.println("总收入:" + totalIncome + "元");
}
public static void main(String[] args) {
CafeManager cafeManager = new CafeManager();
cafeManager.initMenu();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请输入操作编号:1-点餐 2-结账 3-退出");
int op = scanner.nextInt();
if (op == 1) {
cafeManager.showMenu();
cafeManager.placeOrder();
} else if (op == 2) {
cafeManager.checkout();
break;
} else if (op == 3) {
break;
} else {
System.out.println("无效操作,请重新输入!");
}
}
}
}
class Coffee {
private String name; // 名称
private double price; // 价格
public Coffee(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}
class Order {
private Coffee coffee; // 咖啡
private int amount; // 数量
public Order(Coffee coffee, int amount) {
this.coffee = coffee;
this.amount = amount;
}
public Coffee getCoffee() {
return coffee;
}
public int getAmount() {
return amount;
}
public double getTotalPrice() {
return coffee.getPrice() * amount;
}
}
```
这个程序实现了咖啡馆的基本功能,包括初始化咖啡菜单、显示咖啡菜单、点餐、结账等。当用户输入操作编号时,程序会根据用户的选择执行不同的操作。你可以在此基础上进行修改和扩展,实现你自己的咖啡馆管理系统。
阅读全文