/*
1、请用Scanner,while,if,switch做出一个简单的点餐且能结账的小系统;
要求:做到如下功能;
(1)点餐菜单;
(2)点餐数量;
(3)结账;
(4)退出;
*/
package org.lyk;
import java.util.Scanner;
public class DianC {
static int dpdf = 10;// 东坡豆腐价格
static int jbrp = 15;// 椒爆肉片价格
static int sxpg = 10;// 蒜香排骨价格
static int scy = 25;// 酸菜鱼价格
static int szrp = 35;// 水煮肉片价格
static int hspg = 20;// 红烧排骨价格
static int sl;// 点菜数量
static int sum1,sumdp;// 东坡豆腐总价
static int sum2,sumjb;// 椒爆肉片总价
static int sum3,sumsx;// 蒜香排骨总价
static int sum4,sumsc;// 酸菜鱼总价
static int sum5,sumsz;// 水煮肉片总价
static int sum6,sumhs;// 红烧排骨总价
static int sum;// 总价格
// 输入点菜数量
public static void shuliang() {
Scanner s = new Scanner(System.in);
sl = s.nextInt();
}
// 菜单
public static void caidan() {
System.out.println("欢迎进入点餐系统!");
System.out.println("请按照菜单上的序号点餐!");
System.out.println("1.东坡豆腐 " + dpdf + "元" + " 2.椒爆肉片 " + jbrp + "元" + " 3.蒜香排骨 " + sxpg + "元" + "\n" + "4.酸菜鱼 " + scy + "元"+ " 5.水煮肉片 " + szrp + "元" + " 6.红烧排骨 " + hspg + "元");
System.out.println("按0退出点菜结账!");
}
public static void main(String[] args) {
caidan();
Scanner s = new Scanner(System.in);
// int i=s.nextInt();
boolean a = true;
while (a) {
int i = s.nextInt();
switch (i) {
case 0:
System.out.println("退出点菜,结账!");
//计算总共消费价格
sum = sumdp + sumjb + sumsx + sumsc + sumsz + sumhs;
System.out.println("总共消费:" + sum + "元");
a = false;
break;
case 1:
System.out.println("您点的是东坡豆腐.请确认份数!");
shuliang();
sum1 = dpdf * sl;
sumdp+=sum1;
System.out.println("东坡豆腐" + sl + "份," + sum1 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
case 2:
System.out.println("您点的是椒爆肉片.请确认份数");
shuliang();
sum2 = jbrp * sl;
sumjb+=sum2;
System.out.println("椒爆肉片" + sl + "份," + sum2 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
case 3:
System.out.println("您点的是蒜香排骨.请确认份数");
shuliang();
sum3 = sxpg * sl;
sumsx+=sum3;
System.out.println("蒜香排骨" + sl + "份," + sum3 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
case 4:
System.out.println("您点的是酸菜鱼.请确认份数");
shuliang();
sum4 = scy * sl;
sumsc+=sum4;
System.out.println("酸菜鱼" + sl + "份," + sum4 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
case 5:
System.out.println("您点的是水煮肉片.请确认份数");
shuliang();
sum5 = szrp * sl;
sumsz+=sum5;
System.out.println("水煮肉片" + sl + "份," + sum5 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
case 6:
System.out.println("您点的是红烧排骨.请确认份数");
shuliang();
sum6 = hspg * sl;
sumhs+=sum6;
System.out.println("红烧排骨" + sl + "份," + sum6 + "元");
System.out.println("继续点菜,或者按0退出点菜结账");
break;
}
}
}
}
初学者尚有许多不足之处待改进。。。