用JAVA写一个奶茶点单系统
时间: 2023-12-09 12:06:40 浏览: 173
好的,下面是一个简单的奶茶点单系统的JAVA代码:
```java
import java.util.Scanner;
public class MilkTeaOrderingSystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice;
int sugarLevel;
int iceLevel;
boolean addPearl;
double price;
System.out.println("欢迎来到奶茶点单系统!");
do {
System.out.println("请选择您要的奶茶口味:");
System.out.println("1. 原味奶茶");
System.out.println("2. 珍珠奶茶");
System.out.println("3. 草莓奶茶");
System.out.println("4. 巧克力奶茶");
System.out.println("0. 结束点单");
choice = input.nextInt();
switch (choice) {
case 1:
price = 10.0;
break;
case 2:
price = 12.0;
System.out.println("是否加珍珠?(1-是,0-否)");
addPearl = (input.nextInt() == 1);
if (addPearl) {
price += 2.0;
}
break;
case 3:
price = 15.0;
break;
case 4:
price = 18.0;
break;
case 0:
System.out.println("谢谢使用!");
return;
default:
System.out.println("输入有误,请重新输入!");
continue;
}
System.out.println("请选择甜度:");
System.out.println("1. 正常甜");
System.out.println("2. 七分甜");
System.out.println("3. 五分甜");
System.out.println("4. 三分甜");
System.out.println("5. 不加糖");
sugarLevel = input.nextInt();
switch (sugarLevel) {
case 1:
price += 0.5;
break;
case 2:
price += 0.3;
break;
case 3:
price += 0.1;
break;
case 4:
price -= 0.1;
break;
case 5:
break;
default:
System.out.println("输入有误,请重新输入!");
continue;
}
System.out.println("请选择冰量:");
System.out.println("1. 正常冰");
System.out.println("2. 少冰");
System.out.println("3. 去冰");
System.out.println("4. 加热");
iceLevel = input.nextInt();
switch (iceLevel) {
case 1:
break;
case 2:
price += 0.2;
break;
case 3:
price -= 0.5;
break;
case 4:
price += 0.5;
break;
default:
System.out.println("输入有误,请重新输入!");
continue;
}
System.out.printf("您选择的是%d号奶茶,甜度为%d,冰量为%d,价格为%.2f元\n", choice, sugarLevel, iceLevel, price);
} while (choice != 0);
}
}
```
这个程序模拟了一个简单的奶茶点单系统,用户可以选择奶茶口味、甜度、冰量和是否加珍珠,程序会根据用户的选择计算出价格并输出。用户可以选择结束点单。
阅读全文