用JAVA程序设计食堂点餐程序的代码
时间: 2024-03-06 20:48:23 浏览: 23
好的,以下是一个简单的用JAVA编写的食堂点餐程序示例:
```java
import java.util.Scanner;
public class CafeteriaOrderSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int option = 0;
String[] menu = {"炒饭", "炒面", "饺子", "馄饨", "牛肉面", "炒年糕"};
int[] price = {10, 12, 8, 9, 15, 11};
int[] count = {0, 0, 0, 0, 0, 0};
int total = 0;
while (option != 5) {
System.out.println("欢迎使用食堂点餐系统,请输入对应的数字选择操作:");
System.out.println("1. 点餐");
System.out.println("2. 查看订单");
System.out.println("3. 修改订单");
System.out.println("4. 删除订单");
System.out.println("5. 结束点餐");
option = scanner.nextInt();
switch (option) {
case 1:
System.out.println("菜单如下:");
for (int i = 0; i < menu.length; i++) {
System.out.println((i+1) + ". " + menu[i] + " " + price[i] + "元");
}
System.out.println("请输入要点的菜品编号:");
int item = scanner.nextInt();
System.out.println("请输入要点的数量:");
int num = scanner.nextInt();
count[item-1] += num;
total += price[item-1] * num;
System.out.println("点餐成功!");
break;
case 2:
System.out.println("订单如下:");
for (int i = 0; i < menu.length; i++) {
if (count[i] != 0) {
System.out.println(menu[i] + " " + count[i] + "份 " + price[i] + "元/份");
}
}
System.out.println("总计:" + total + "元");
break;
case 3:
System.out.println("请输入要修改的菜品编号:");
int item2 = scanner.nextInt();
System.out.println("请输入修改后的数量:");
int num2 = scanner.nextInt();
total -= price[item2-1] * count[item2-1];
count[item2-1] = num2;
total += price[item2-1] * count[item2-1];
System.out.println("修改成功!");
break;
case 4:
System.out.println("请输入要删除的菜品编号:");
int item3 = scanner.nextInt();
total -= price[item3-1] * count[item3-1];
count[item3-1] = 0;
System.out.println("删除成功!");
break;
case 5:
System.out.println("感谢使用食堂点餐系统,再见!");
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
}
```
这个程序模拟了一个简单的食堂点餐系统,可以实现点餐、查看订单、修改订单和删除订单等功能。您可以根据具体需求对程序进行修改和完善。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)