吃货联盟
public class eat { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] names = new String[4]; // 订餐人名字 String[] dishMegs = new String[4]; // 保存所选的信息,包括菜品名及份数 int[] times = new int[4]; // 保存订餐时间 double[] sumPrices = new double[4]; // 订餐总金额 String[] addresses = new String[4]; // 送餐地址 int[] states = new int[4]; // 保存订单状态:0.表示已预订,1.表示已完成 names[0] = "张晴"; dishMegs[0] = "红烧带鱼2份"; times[0] = 12; addresses[0] = "天成路207号"; sumPrices[0] = 76.0; states[0] = 1; // 初始化第二条信息 names[1] = "张晴"; dishMegs[1] = "红烧带鱼2份"; times[1] = 18; addresses[1] = "天成路207号"; sumPrices[1] = 76.0; states[1] = 0; String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" }; // 菜品名称 double[] prices = new double[] { 38.0, 20.0, 10.0 }; // 菜品单价 int[] praiseNums = new int[3]; int num = -1; // 用户输入0返回主菜单,否则退出系统 boolean isExit = false; // 标志用户是否退出系统: true:退出系统 System.out.println("\n欢迎使用“吃货联盟订餐系统”"); int number = 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("请选择:"); num = input.nextInt(); switch (num) { case 1: boolean isAdds = false; String name = ""; for (int j = 0; j < names.length; j++) { if (names[j] == null) { // 添加订单信息 isAdds = true; System.out.println("请输入订餐人名字:"); name = input.next(); // 显示菜单信息 System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数"); for (int i = 0; i < dishNames.length; i++) { String price = prices[i] + "元"; String priaiseNums = (praiseNums[i]) > 0 ? praiseNums[i] + "赞" : "0"; System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + price + "\t" + priaiseNums); } // 用户点菜 System.out.println("请选择您要点的菜品编号"); int chooesDish = input.nextInt(); System.out.println("请选择你需要的份数:"); int numbers = input.nextInt(); String dishMeg = dishNames[chooesDish - 1] + " " + numbers + "份"; double sumPrice = prices[chooesDish - 1] * numbers; // 餐费满50元,免送餐费5元 double deliCharge = (sumPrice >= 50) ? 0 : 5; System.out.println("请输入送餐时间(送餐时间是10点到20点间整点送餐):"); int time = input.nextInt(); while (time < 10 || time > 20) { System.out.println("您输入有误,请输入10~20间的整数!"); time = input.nextInt(); } System.out.println("请输入送货餐地址:"); String addresses1 = input.next(); System.out.println("订餐成功!"); System.out.println("您订的是:" + dishMeg); System.out.println("您的送餐时间:" + time + "点"); System.out.println("餐费:" + sumPrice + "元,送餐费" + deliCharge + "元,总计:" + (sumPrice + deliCharge) + "元"); names[j] = name; dishMegs[j] = dishMeg; times[j] = time; addresses[j] = addresses1; sumPrices[j] = sumPrice + deliCharge; break; } } if (!isAdds) { System.out.println("对不起,您的餐袋已满!"); isAdds = false; } else { isAdds = true; } break; case 2: System.out.println("***查看餐袋***"); System.out.println("序号\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 day = times[i] + "日"; String sumPrice1 = sumPrices[i] + "元"; System.out.println((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + day + "\t" + addresses[i] + "\t" + sumPrice1 + "\t" + state); } } break; case 3: boolean isadd = false; // 找到签收订单 System.out.println("请选择你要签收的订单:"); int isgnorderid = input.nextInt(); for (int i = 0; i < names.length; i++) { if (names[i] != null && states[i] == 0 && isgnorderid == i + 1) { states[i] = 1; // 将状态置为完成 System.out.println("订单签收成功!"); isadd = true; // 标记已找到账单 } else if (names[i] != null && states[i] == 1 && isgnorderid == i + 1) { System.out.println("您选择的订单已完成签收,不能再次签收!"); isadd = true; // 标记已找到此账单 } } if (!isadd) { System.out.println("您选择的账单不存在!"); } break; case 4: boolean isAdd = false; // 删除订单// 标记是否找到要删除的订单 System.out.println("请选择要删除的订单:"); int delId = input.nextInt(); for (int i = 0; i < names.length; i++) { if (names[i] != null && states[i] == 1 && delId == i + 1) { isAdd = 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]; sumPrices[j] = sumPrices[j + 1]; // 最后一位清空 } int endIndex = names.length - 1; names[endIndex] = null; dishMegs[endIndex] = null; times[endIndex] = 0; addresses[endIndex] = null; states[endIndex] = 0; sumPrices[endIndex] = 0; System.out.println("删除订单成功!"); break; } else if (names[i] != null && states[i] == 0 && delId == i + 1) { System.out.println("您选择的订单未签收,不能删除!"); isAdd = true; // 标记已找到账单 break; } } if (!isAdd) { System.out.println("您要删除的账单不存在!"); } break; case 5: System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t"); for (int i = 0; i < dishNames.length; i++) { String price = prices[i] + "元"; String priaiseNum = (praiseNums[i]) > 0 ? praiseNums[i] + "赞" : ""; System.out.println((i + 1) + "\t" + dishNames[i] + "\t" + price + "\t" + priaiseNum); } System.out.println("请选择您要点赞的菜品序号:"); int priaiseNum = input.nextInt(); praiseNums[priaiseNum - 1]++; // 赞数加一 System.out.println("点赞成功!"); break; case 6: isExit = true; break; default: // 退出系统 isExit = true; break; } if (!isExit) { System.out.print("输入0返回:"); num = input.nextInt(); } else { break; } } while (num == 0); System.out.println("退出系统,谢谢使用!"); } }
posted on 2017-08-22 14:21 雅俗共赏_house 阅读(245) 评论(0) 编辑 收藏 举报