奶茶点单程序Java
时间: 2023-08-08 17:08:05 浏览: 206
以下是一个简单的奶茶点单程序的Java代码实现:
```java
import java.util.Scanner;
public class MilkTeaOrder {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] milkTeas = {"原味奶茶", "四季奶青", "珍珠奶茶", "红豆奶茶", "芒果奶茶"};
double[] prices = {9.9, 10.5, 11.0, 11.0, 12.0};
int[] amounts = new int[milkTeas.length];
System.out.println("欢迎光临!以下是我们的奶茶菜单:");
for (int i = 0; i < milkTeas.length; i++) {
System.out.println(i + 1 + ". " + milkTeas[i] + "\t\t" + prices[i] + "元/杯");
}
while (true) {
System.out.print("请输入您要购买的奶茶序号(输入0结束点单):");
int choice = input.nextInt();
if (choice == 0) {
break;
}
System.out.print("请输入购买数量:");
int amount = input.nextInt();
amounts[choice - 1] += amount;
}
System.out.println("您的订单:");
double total = 0;
for (int i = 0; i < milkTeas.length; i++) {
if (amounts[i] > 0) {
System.out.println(milkTeas[i] + "\t\t" + prices[i] + "元/杯\t\t" + amounts[i] + "杯\t\t" + prices[i] * amounts[i] + "元");
total += prices[i] * amounts[i];
}
}
System.out.println("总计:" + total + "元。");
System.out.println("感谢惠顾,欢迎下次光临!");
}
}
```
该程序会先输出奶茶菜单,然后循环让用户输入要购买的奶茶序号和数量,直到用户输入0为止。程序会记录用户购买的每种奶茶的数量,并在最后输出整个订单,并计算出总金额。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)