吃货联盟案例分析
public class chiHuo1 {
public static void main(String[] args) {
final double NO_SEND_MONEY=80;
String[] dishes={"东坡肉","地锅鸡","水煮鱼","佛跳墙"};
double[] prices={45,38,28,99};
int[] like={11,22,33,44,};
int choseNum=0;
String[][] bills=new String[1024][];
String name=null;
int pcs=0;
int time=0;
String address=null;
String status=null;
Scanner sc=new Scanner(System.in);
int chose=0;
do {
System.out.println("欢迎使用吃货联盟订餐系统");
System.out.println("************************************");
System.out.println("1、我要订餐");
System.out.println("2、查看餐袋");
System.out.println("3、签收订单");
System.out.println("4、删除订单");
System.out.println("5、我要点赞");
System.out.println("6、退出系统");
System.out.println("************************************");
System.out.println("请选择:");
chose=sc.nextInt();
switch (chose){
case 1:
System.out.println("***我要订餐***");
System.out.print("请输入订餐人姓名:");
name=sc.next();
System.out.println("序号\t菜品\t单价");
for (int i = 0; i < dishes.length; i++) {
System.out.println((i+1)+"\t"+dishes[i]+"\t"+ prices[i]);
}
do {
System.out.println("请输入您要点的菜品编号:");
choseNum=sc.nextInt();
if (choseNum>0 && choseNum<=dishes.length)break;
System.out.println("您的输入有误,请重新输入!");
}while (true);
do {
System.out.println("请选择您需要的份数:");
pcs=sc.nextInt();
if (pcs>0) break;
System.out.println("份数不能小于0,请重新输入");
}while (true);
do {
System.out.println("请输入送餐时间(10点到20点整点送餐):");
time=sc.nextInt();
if (time>=10 && time<=20)break;
System.out.println("输入有误,重新输入!");
}while (true);
System.out.println("请输入送餐地址:");
address=sc.next();
System.out.println("订餐成功!");
System.out.println("您订的是:"+dishes[choseNum-1]+pcs+"份");
System.out.println("送餐时间:"+time+"点");
double dishPrice=prices[choseNum-1]*pcs;
int sendMoney=0;
if (dishPrice<NO_SEND_MONEY){
sendMoney=6;
}
double totalPrice=dishPrice+sendMoney;
System.out.println("餐费:"+dishPrice+"元,送餐费"+sendMoney+"元,总计:"+totalPrice+"元");
//插入订单,遍历订单,如果为空,则插入
for (int i = 0; i < bills.length; i++) {
if (bills[i]==null){
bills[i]=new String[7];
bills[i][0]=name;
bills[i][1]=dishes[choseNum-1]+" "+pcs+"份";
bills[i][2]=time+"点";
bills[i][3]=address;
bills[i][4]=totalPrice+"元";
bills[i][5]="已预定";
break;
}
}
System.out.println("输入0返回:");
chose=sc.nextInt();
break;
case 2:
System.out.println("***查看餐袋***");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
for (int i = 0; i < bills.length; i++) {
if (bills[i]==null){
break;
}
System.out.println(i+1+"\t"+"\t"+bills[i][0]+"\t"+"\t"+"\t"+bills[i][1]+"\t"+"\t"+bills[i][2]+"\t"
+"\t"+bills[i][3]+"\t"+"\t"+bills[i][4]+"\t"+"\t"+bills[i][5]);
}
System.out.println("输入0返回:");
chose=sc.nextInt();
break;
case 3:
System.out.println("***签收订单***");
if (bills[0]==null){
System.out.println("订单为空,不能签收!");
System.out.println("***输入0返回***");
chose=sc.nextInt();
break;
}
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t总金额\t\t订单状态");
int i = 0;
for ( ;i < bills.length; i++) {
if (bills[i]==null){
break;
}
System.out.println(i+1+"\t"+"\t"+bills[i][0]+"\t"+"\t"+"\t"+
bills[i][1]+"\t"+"\t"+bills[i][4]+"\t"+"\t"+bills[i][5]);
}
int signNum;
do {
System.out.println("请选择要签收的订单编号:");
signNum=sc.nextInt();
if (signNum>0 && signNum<=i)break;
System.out.println("订单不存在,重新输入!!");
}while (true);
if (bills[signNum-1][5].equals("已完成"))
System.out.println("订单已签收,不需重复签收");
else
bills[signNum-1][5]="已完成";
System.out.println("输入0返回:");
chose=sc.nextInt();
break;
case 4:
System.out.println("***删除订单***");
if (bills[0]==null){
System.out.println("订单为空,不能删除!");
System.out.println("***输入0返回***");
chose=sc.nextInt();
break;
}
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t总金额\t\t订单状态");
int k = 0;
for ( ;k < bills.length; k++) {
if (bills[k]==null){
break;
}
System.out.println(k+1+"\t"+"\t"+bills[k][0]+"\t"+"\t"+"\t"+
bills[k][1]+"\t"+"\t"+bills[k][4]+"\t"+"\t"+bills[k][5]);
}
int delNum;
do {
System.out.println("请选择要删除的订单编号:");
delNum=sc.nextInt();
if (bills[0]==null){
break;
}
if (delNum>0 && delNum<=k)break;
System.out.println("订单不存在,重新输入!!");
}while (true);
//未完成的订单不能删除
//删除点歌单需要考虑选择的订单删除后,后面的订单需要前移
if (!bills[delNum-1][5].equals("已完成"))
System.out.println("未完成的订单不能删除!");
else{
for (int s = delNum-1 ; bills[s]!=null ; s++) {
if (delNum==bills.length){
bills[delNum-1]=null;
}else{
bills[s]=bills[s+1];
}
}
System.out.println("删除完成!");
}
System.out.println("输入0返回:");
chose=sc.nextInt();
break;
case 5:
System.out.println("***我要点赞***");
System.out.println("序号\t菜品\t\t单价\t点赞数");
for (int j = 0; j < dishes.length; j++) {
System.out.println((j+1)+"\t"+dishes[j]+"\t"+ prices[j]+"元"+"\t"+like[j]);
}
int likeNum;
do {
System.out.println("请选择要点赞的菜品:");
likeNum=sc.nextInt();
if (likeNum>0 && likeNum<=like.length)break;
System.out.println("没有这个菜品请重新输入:");
}while (true);
like[likeNum-1]++;
System.out.println("谢谢点赞!");
System.out.println("输入0返回:");
chose=sc.nextInt();
break;
}
}while (chose==0);
System.out.println("谢谢使用,欢迎您下次光临!");
}
}