1. 吃货联盟系统6个功能调通
2. 升级查看餐袋功能:根据订餐人姓名查询,查到显示订单详细信息,未查到给出相应提示
//我要订餐
//查看餐袋
//签收订单
//删除订单
//我要点赞
//退出系统
import java.util.Scanner; public class Demo01 { public static void main(String[] args) { String menu = "*************吃货联盟订餐系统************\n" + "1.我要订餐\n" + "2.查看餐袋\n" + "3.签收订单\n" + "4.删除订单\n" + "5.我要点赞\n" + "6.退出系统\n" + "****************************************"; boolean flag = false; String[] foodNames = {"烤串", "火锅", "担担面", "牛肉板面", "尖椒肉丝"};//菜品 double[] prices = {30, 108.8, 12, 18, 25};//价格 String[] userName = new String[10];//点餐人姓名 int[] foodid = new int[10];//点的菜品编号 int[] fen = new int[10];//点的份数 int[] times = new int[10];//送餐时间 String[] address = new String[10];//送餐人地址 double[] userSumPrice = new double[10];//订单总价 int[] userStatus = new int[10];//订单状态,已预订0,已完成1 int[] dianZan = new int[10];//点赞数 do { System.out.println(menu); Scanner scanner = new Scanner(System.in); System.out.print("请输入1~6:"); int num1 = scanner.nextInt(); switch (num1) { case 1: System.out.println("编号\t菜品名\t\t单价"); for (int i = 0; i < foodNames.length; i++) { System.out.println((i + 1) + "\t\t" + foodNames[i] + "\t\t" + prices[i] + ""); } int index = -1; for (int i = 0; i < userName.length; i++) { if (userName[i] == null) { index = i; System.out.print("请输入菜品编号:"); foodid[i] = scanner.nextInt(); System.out.print("请输入订餐姓名:"); userName[i] = scanner.next(); System.out.print("请输入订餐份数:"); fen[i] = scanner.nextInt(); System.out.print("请输入送餐时间:"); times[i] = scanner.nextInt(); System.out.print("请输入送餐地址:"); address[i] = scanner.next(); userStatus[i] = 0; userSumPrice[i] = fen[i] * prices[foodid[i] - 1]; break; } } System.out.println("订单信息:"); System.out.println("姓名:" + userName[index] + ",菜品:" + foodNames[foodid[index] - 1] + ",份数:" + fen[index] + ",时间:" + times[index] + ",地址:" + address[index] + ",总价:" + userSumPrice[index]); break; case 2: System.out.println("编号\t" + "姓名\t" + "菜品\t" + "份数\t" + "时间\t" + "地址\t" + "状态\t" + "总价\t"); for (int i = 0; i < userName.length; i++) { if (userName[i] == null) { break; } else { //状态如果是0,st值为已预订,如果不是就是已完成 String st = userStatus[i] == 0 ? "已预订" : "已完成"; System.out.println((i + 1) + "\t\t" + userName[i] + "\t\t" + foodNames[foodid[i] - 1] + "\t" + fen[i] + "\t\t" + times[i] + "\t\t" + address[i] + "\t" + st + "\t" + userSumPrice[i]); } } break; case 3: while (true) { System.out.print("请输入要签收的订单编号:"); int dingDanId = scanner.nextInt(); if (userStatus[dingDanId - 1] == 1) { System.out.println("不能重复签收"); continue; } userStatus[dingDanId - 1] = 1; for (int i = 0; i < userName.length; i++) { if (userName[i] == null) { break; } else { //状态如果是0,st值为已预订,如果不是就是已完成 String st = userStatus[i] == 0 ? "已预订" : "已完成"; System.out.println((i + 1) + "\t\t" + userName[i] + "\t\t" + foodNames[foodid[i] - 1] + "\t" + fen[i] + "\t\t" + times[i] + "\t\t" + address[i] + "\t" + st + "\t" + userSumPrice[i]); } } break; } break; case 4: System.out.print("请输入要要删除的订单编号:"); int dingDanId = scanner.nextInt(); if (userStatus[dingDanId - 1] == 1) { for (int i = dingDanId - 1; i < userName.length; i++) { if (dingDanId == userName.length || userName[i + 1] == null) { userName[i] = null; foodid[i] = 0; fen[i] = 0; times[i] = 0; userStatus[i] = 0; address[i] = null; userSumPrice[i] = 0.0; break; } else { userName[i] = userName[i + 1]; foodid[i] = foodid[i + 1]; fen[i] = fen[i + 1]; times[i] = times[i + 1]; userStatus[i] = userStatus[i + 1]; address[i] = address[i + 1]; userSumPrice[i] = userSumPrice[i + 1]; } } System.out.println(dingDanId + "删除成功"); } else { System.out.println("不能删除未签收的订单"); } break; case 5: System.out.println("编号\t\t" + "菜品\t\t" + "单价\t\t" + "点赞数"); for (int i = 0; i < foodNames.length; i++) { System.out.println((i + 1) + "\t\t\t" + foodNames[i] + "\t\t" + prices[i] + "\t\t" + dianZan[i]); } System.out.print("请输入要点赞的菜品编号:"); int dzid = scanner.nextInt(); dianZan[dzid - 1] += 1; System.out.println("编号\t\t" + "菜品\t\t" + "单价\t\t" + "点赞数"); for (int i = 0; i < foodNames.length; i++) { System.out.println((i + 1) + "\t\t\t" + foodNames[i] + "\t\t" + prices[i] + "\t\t" + dianZan[i]); } break; case 6: System.out.println("谢谢惠顾,再见"); flag = true; break; default: System.out.println("您输入的数字有误,请重新输入(1~6)"); } } while (!flag); } } import java.util.Arrays; import java.util.Scanner; public class HomeWork8_29 { public static void main(String[] args) { String menu="=======吃货联盟订餐系统============\n"+ "1.我要订餐\n"+ "2.查看餐袋\n"+ "3.签收订单\n"+ "4.删除订单\n"+ "5.我要点赞\n"+ "6.退出系统\n"+ "==============================="; boolean flag=false; String[] foodNames={"烤 串","火 锅","担担面","牛肉板面","擦仡斗"}; double[] prices={3,108.1,12,18,8}; String[] username=new String[10]; int[] foodid=new int[10]; int[] fen=new int[10]; int[] times=new int[10]; String[] address=new String[10]; double[] usersumprice= new double[10]; int[] userstatus = new int[10]; int[] dianZan=new int[10]; do{ System.out.println(menu); Scanner scanner=new Scanner(System.in); System.out.print("请输入1-6:"); int num= scanner.nextInt(); switch (num){ case 1: System.out.println("编号\t菜品名\t\t单价"); for (int i = 0; i < foodNames.length ; i++) { System.out.println(i+1+"\t"+foodNames[i]+"\t\t"+prices[i]); } int index=-1; for (int i = 0; i <username.length ; i++) { if (username[i]==null){ index=i; System.out.print("请输入菜品编号:"); foodid[i]= scanner.nextInt(); System.out.print("请输入订餐份数:"); fen[i]= scanner.nextInt(); System.out.print("请输入订餐姓名:"); username[i]= scanner.next(); System.out.print("请输入送餐时间:"); times[i]= scanner.nextInt(); System.out.print("请输入送餐地址:"); address[i]= scanner.next(); userstatus[i]=0; usersumprice[i]=fen[i]*prices[foodid[i]-1]; break; } } System.out.println("订单信息:"); System.out.println("姓名:"+username[index]+",菜品:"+foodNames[foodid[index]-1]+",份数:"+fen[index]+",时间:"+times[index]+",地址:"+address[index]+",总价:"+usersumprice[index]); break; case 2: System.out.print("请输入要查询订单的姓名:"); String name= scanner.next(); int index1=-1; try { for (int j = 0; j < username.length; j++) { if(username[j].equals(name)){ index1 = j; String st = userstatus[index1]==0 ?"已预定":"已完成"; System.out.println("姓名:"+username[index1]+",菜品:"+foodNames[foodid[index1]-1]+",份数:"+fen[index1]+",时间:"+times[index1]+",地址:"+address[index1]+",总价:"+usersumprice[index1]+",状态:"+st); System.out.println("订单信息:"); break; } if(index1<0){ System.out.println("不存在用户信息"); } } }catch (Exception e){ System.out.println("不存在用户信息"); continue; } break; case 3: System.out.print("请输入签收要订单的姓名:"); String name1= scanner.next(); for (int i = 0; i <username.length; i++) { if (username[i].equals(name1)&&userstatus[i]==1){ System.out.println("不能重复签收"); break; } userstatus[i]=1; if (username[i].equals(name1)){ String st=userstatus[i]==0?"已预定":"已完成"; System.out.println("订单信息:"); System.out.println("姓名:"+username[i]+",菜品:"+foodNames[i]+",份数:"+fen[i]+",时间:"+times[i]+",地址:"+address[i]+",总价:"+usersumprice[i]+"状态:"+st); break; } } break; case 4: System.out.print("请输入要要删除的姓名:"); String name2 = scanner.next(); for (int i = 0; i <username.length ; i++) { if (username[i].equals(name2)){ if (userstatus[i] == 1) { for (int j = i; j < username.length; j++) { if (i+1 == username.length || username[j + 1] == null) { username[j] = null; foodid[j] = 0; fen[j] = 0; times[j] = 0; userstatus[j] = 0; address[j] = null; usersumprice[j] = 0.0; break; } else { username[j] = username[j + 1]; foodid[j] = foodid[j + 1]; fen[j] = fen[j + 1]; times[j] = times[j + 1]; userstatus[j] = userstatus[j + 1]; address[j] = address[j + 1]; usersumprice[j] = usersumprice[j + 1]; } } System.out.println(name2 + "删除成功"); } else { System.out.println("不能删除未签收的订单"); } } break; } break; case 5: System.out.println("编号\t\t" + "菜品\t\t" + "单价\t\t" + "点赞数"); for (int i = 0; i < foodNames.length; i++) { System.out.println((i+1) + "\t\t\t" + foodNames[i] + "\t\t" + prices[i] + "\t\t" + dianZan[i]); } System.out.print("请输入要点赞订单姓名:"); String name3 = scanner.next(); for (int i = 0; i <username.length ; i++) { if (username[i].equals(name3)){ dianZan[foodid[i]-1] += 1; } System.out.println("编号\t\t" + "菜品\t\t" + "单价\t\t" + "点赞数"); for (int j = 0; j < foodNames.length; j++) { System.out.println((j+1) + "\t\t\t" + foodNames[j] + "\t\t" + prices[j] + "\t\t" + dianZan[j]); } break; } break; case 6: System.out.print("谢谢惠顾"); flag=true; break; default: System.out.println("输入有误,请重新输入1-6:"); } }while (!flag); } }
标签:userName,联盟,int,系统,吃货,System,println,new,out From: https://www.cnblogs.com/hsk991213/p/17668463.html