package CRJ;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* 点菜主程序
* */
public class DishApp {
//定义集合(表示拥有的菜品)
static List<Dish> dishList = new ArrayList<>();
//用户点的
static List<Dish> personDish = new ArrayList<>();
//提起那准备一些菜品,展示
public static void main(String[] args) {
//初始化一些菜品
initDish();
//创建一个扫描器
Scanner s = new Scanner(System.in);
while (true) {
showMenu();
//获取内容
int num = s.nextInt();
switch (num) {
case 1:
while (true) {
showDishMenu();
//获取用户输入的内容
int id=s.nextInt();
if(id==0) {
break;
}
Dish dish = dishList.get(id - 1);
System.out.println("你点了"+dish.name+"菜");
personDish.add(dish);
}
case 2:
//以点菜品
showPersonDish();
break;
case 3:
//买单
buy();
return;
default:
System.out.println("请重新输入");
break;
}
}
}
private static void showDishMenu() {
System.out.println("----请点菜----");
//遍历集合
for (int i = 0; i < dishList.size(); i++) {
//从集合中使用i获取每一个菜品对象
Dish dish = dishList.get(i);
System.out.print(dish.id + "\t" + dish.name + "\t" + dish.price + "\n");
}
System.out.println("----输入序号点菜,按0返回上一级---");
}
private static void showPersonDish() {
System.out.println("---你已点---");
for (Dish dish : personDish) {
System.out.println(dish.id+"\t"+dish.name+"\t"+dish.price);
}
}
private static void buy() {
System.out.println("结账");
double sum=0f;
for (Dish dish : personDish) {
sum +=+dish.price;
}
System.out.println("总价为"+sum+"元");
}
private static void showMenu() {
System.out.println("----主菜单----");
System.out.println("菜单\t\t\t 1");
System.out.println("已点菜品\t\t 2");
System.out.println("买单\t\t\t 3");
System.out.println("--根据编号请选择服务--");
}
//初始化一些菜品
public static void initDish() {
Dish dish = new Dish(1, "香辣肉丝", 29.99);
Dish dish2 = new Dish(2, "酸菜鱼", 39.99);
Dish dish3 = new Dish(3, "鱼香肉丝", 49.99);
dishList.add(dish);
dishList.add(dish2);
dishList.add(dish3);
dishList.add(new Dish(4, "拌凉菜", 12.66));
dishList.add(new Dish(5, "炒鸡蛋", 12.77));
dishList.add(new Dish(6, "地三鲜", 32.88));
}
}