标签:结果 order || pac package 状态 *** 系统 names
package Game; import java.util.Scanner; public class Chihuo { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String [] names = new String[4];//保存订餐人姓名 String [] dishMegs = new String[4];//菜名 int [] times = new int[4];//送餐时间 String [] addresses = new String[4];//送餐地址 int [] states = new int[4];//订单状态:0表示已经预定,1表示已经完成 double [] sumPrices = new double[4];//订单总金额 double []prices = {15.0,20.9,18.0}; int [] zans = new int[3];//点赞数 String [] food = {"小炒肉","尖椒牛肉","红烧肉"}; //初始化第一条订单信息 names[0] = "小李"; dishMegs[0] = "小炒肉1份"; times[0] = 10; addresses[0] = "观日路48号"; states[0] = 1; sumPrices[0] = 15.0; //初始化第二条订单信息 names[1] = "小王"; dishMegs[1] = "尖椒牛肉1份"; times[1] = 18; addresses[1] = "会展路100号"; states[1] = 0; sumPrices[1] = 20.9; int num = -1; boolean isExit = false; System.out.println("\n 欢迎使用“吃货联盟订餐系统”"); do { System.out.println("***********************"); System.out.println("1、我要订餐\n" + "2、查看菜单\n" + "3、签收订单\n" + "4、删除订单\n" + "5、我要点赞\n" + "6、退出系统"); System.out.println("***********************"); System.out.println("请选择:"); int choose = sc.nextInt(); switch(choose) { case 1: //我要订餐 System.out.println("*****我要订餐*****"); boolean isAdd = false;//记录是否可以订餐 for(int i = 0;i<names.length;i++) { if(names[i]==null) { isAdd = true; System.out.println("订餐人姓名为:"); String name = sc.next(); //显示提供选择菜品信息 System.out.println("序号\t" + "菜名\t" + "单价\t" + "点赞数"); for(int j =0;j<food.length;j++) { String price = prices[j]+"元"; String zan = zans[j] > 0?zans[j]+"赞":"0"; System.out.println((j+1)+"\t"+food[j]+"\t"+price+"\t"+zan); } //用户点菜 System.out.print("请选择你要点的菜品编号:"); int chooseDish = sc.nextInt(); System.out.println("你要点的份数"); int fenshu = sc.nextInt(); String dishMeg = food[chooseDish-1]+""+fenshu+"份"; double sumPrice = prices[chooseDish-1]*fenshu; //餐费满50元,免送餐费5元 double deliCharge = (sumPrice>=50)?0:5; System.out.println("请输入送餐时间(送餐时间是10点至20点间整点送餐):"); int time = sc.nextInt(); while(time<10||time>20) { System.out.println("你的输入有误,请输入10-20间的整数!"); time = sc.nextInt(); } System.out.println("请输入送餐地址:"); String address = sc.next(); System.out.println("订餐成功!"); System.out.println("您订的是:"+dishMeg); System.out.println("送餐时间:"+time+"点"); System.out.println("餐费:"+sumPrice+"元,送餐费"+deliCharge+"元,总计:"+(sumPrice+deliCharge)+"元。"); //添加数据 names[i] = name; dishMegs[i] = dishMeg; times[i] = time; addresses[i] = address; sumPrices[i] = sumPrice+ deliCharge; break; } } if(!isAdd) { System.out.println("对不起你的菜单已满!"); } break; case 2: //查看菜单 System.out.println("*****查看菜单*****"); System.out.println("序号\t\t订餐人\t\t所订餐品\t\t\t送餐时间\t\t送餐地址\t\t\t\t总金额\t\t订单状态"); for(int i=0;i<names.length;i++) { if(names[i]!=null) { String state = (states[i]==0)?"已预订":"已完成"; String date = times[i]+"点"; String sumPrice = sumPrices[i]+"元"; System.out.println((i+1)+"\t\t"+names[i]+"\t\t" + dishMegs[i]+"\t\t"+date+"\t\t"+addresses[i]+"\t\t\t"+"\t" +sumPrice+"\t\t" +state); } } break; case 3: //签收订单 System.out.println("*****签收订单*****"); boolean isSignFind = false;//找到要签收的订单 System.out.print("请选择要签收的订单序号:"); int signOrderld = sc.nextInt(); for(int i=0;i<names.length;i++) { //状态为已预订,序号为用户输入的订单序号减一:可签收 //状态为已完成,序号为用户输入的订单序号减一:不可签收 if(names[i]!=null&&states[i]==0&&signOrderld==i+1) { states[i] = 1;//将状态值设置为已完成 System.out.println("订单签收成功!"); isSignFind= true;//标记已找到此订单 }else if (names[i]!=null&&states[i]==1&&signOrderld==i+1) { System.out.println("你选择的订单已经签收。不可再签收"); isSignFind = true; } } //未找到的订单:不可签收 if(!isSignFind) { System.out.println("你选择的订单不存在!"); } break; case 4: //删除订单 System.out.println("*****删除订单*****"); boolean isDelFind = true; System.out.print("请输入要删除的订单序号:"); int delId = sc.nextInt(); for(int i=0;i<names.length;i++){ //状态值为已完成 序号值为用户输入的序号:可删除 //状态值为已预定 序号值为用户输入的序号:不可删除 if(names[i]!=null && states[i]==1 && delId==i+1){ isDelFind = true; //执行删除操作:删除位置后的元素依次前移 for(int j=delId-1;j<names.length-1;j++){ names[j] = names[j+1]; dishMegs[j] = dishMegs[j+1]; times[j] = times[j+1]; addresses[j] = addresses[j+1]; states[j] = states[j+1]; } //最后一位清空 names[names.length-1] = null; dishMegs[names.length-1] = null; times[names.length-1] = 0; addresses[names.length-1] = null; states[names.length-1] = 0; System.out.println("删除订单成功!"); break; }else if(names[i]!=null && states[i]==0 && delId==i+1){ System.out.println("您选择的订单未签收,不能删除!"); isDelFind = true; break; } } //未找到该序号的订单:不能删除 if(!isDelFind){ System.out.println("您要删除的订单不存在!"); }; break; case 5: //我要点赞 System.out.println("*****我要点赞*****"); // 显示菜品信息 System.out.println("序号" + "\t" + "菜名"+"\t"+"单价"); for (int i = 0; i < food.length; i++) { String price = prices[i] + "元"; String priaiseNum = (zans[i]) > 0 ? zans[i] + "赞" : ""; System.out.println((i + 1) + "\t" + food[i] + "\t" +price+"\t"+ priaiseNum); } System.out.print("请选择您要点赞的菜品序号:"); int priaiseNum = sc.nextInt(); zans[priaiseNum-1]++; //赞数加1 System.out.println("点赞成功!"); break; case 6: //退出系统 isExit = true; System.out.println("谢谢使用,欢迎下次光临!!"); break; default: //退出系统 isExit = true; break; } if(!isExit) { System.out.println("输入0返回:"); num = sc.nextInt(); }else { break; } }while(num==0); } }
输出结果
标签:结果 order || pac package 状态 *** 系统 names
原文地址:https://www.cnblogs.com/hxtzzz/p/11146132.html