import java.util.Scanner;
public class day08zy {
public static void main(String[] args) {
int size = 50;
String[] orderNameArray = new String[size];//菜品名称
String[] orderNumberArray = new String[size];//菜品数量
String[] orderPriceArray = new String[size];//菜品价格
String[] orderTimeArray = new String[size];//送餐时间
String[] orderWayArray = new String[size];//送餐地址
String[] orderDianzanArray = new String[size];//点赞数
String[] orderPhoneArray = new String[size];//送餐电话
String[] orderManArray = new String[size];
orderNameArray[0] = “惠林顿牛排”;
orderNumberArray[0] = “2”;
orderPriceArray[0] = “500”;
orderTimeArray[0] = “2021年7月19日”;
orderWayArray[0] = “汤臣一品”;
orderDianzanArray[0] = “100”;
orderPhoneArray[0] = “15002711507”;
orderManArray[0] = “川哥”;
boolean isExit = false; while (!isExit) { Scanner sc = new Scanner(System.in); 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.删除订单"); String choice = sc.nextLine(); switch (choice) { case "1": int tempIndex = -1; //循环遍历数组,查看应该存在的位置,第一次 null 值出现的位置 for (int i = 0; i < orderNameArray.length; i++) { //如果为null,当前的下标位置就是 i 的值 if (orderNameArray[i] == null) { tempIndex = i; //跳出for循环 break; } } //判断一下 if (tempIndex == -1) { System.out.println("订单已装满..."); //跳出switch语句 break; } //键盘录入数据啦 System.out.println("请输入订单的菜品名称:"); orderNameArray[tempIndex] = sc.nextLine(); System.out.println("请输入订单的数量:"); orderNumberArray[tempIndex] = sc.nextLine(); System.out.println("请输入订单的价格:"); orderPriceArray[tempIndex] = sc.nextLine(); System.out.println("请输入订单的时间:"); orderTimeArray[tempIndex] = sc.nextLine(); System.out.println("请输入送餐的地址:"); orderTimeArray[tempIndex] = sc.nextLine(); System.out.println("请输入姓名:"); orderManArray[tempIndex] = sc.nextLine(); System.out.println("请输入电话:"); orderPhoneArray[tempIndex] = sc.nextLine(); System.out.println("下单成功!"); break; case "2": //判断内容是否全部是 null 值,如果全部是 null 值,则表示没有商品,如果没有商品,后续的代码不再执行 int count = 0; for (int i = 0; i < orderNameArray.length; i++) { if (orderNameArray[i] == null) { count++; } } //最后当 count == size 也就是20相等的话,表示全部是null if (count == size) { System.out.println("当前没有添加订单,请先添加订单"); break; } System.out.println("编号\t菜品名称\t菜品数量\t菜品价格\t订餐时间\t订餐人地址\t订餐人姓名\t订餐人联系电话"); //定义总价格 double sum = 0; for (int i = 0; i < orderNameArray.length; i++) { String name = orderNameArray[i]; if (name == null) { continue; } String number = orderNumberArray[i]; String price = orderPriceArray[i]; String time = orderTimeArray[i]; String Way = orderWayArray[i]; String Man = orderManArray[i]; String Phone = orderPhoneArray[i]; String index = (i + 1) + ""; Double s1 =Double.parseDouble(orderNumberArray[i]); Double s2 =Double.parseDouble(orderPriceArray[i]); sum += s1*s2; System.out.println(index + "\t\t" + name + "\t\t" + number + "\t\t" + price + "\t" + time + "\t" + Way + "\t" + Man + "\t\t" + Phone); } System.out.println("商品总价格:¥" + sum + "元"); break; case "3": System.out.println("已完成"); break; case "4": System.out.println("请输入要删除的订单号:"); Scanner scanner = new Scanner(System.in); int b = scanner.nextInt(); orderNameArray[b - 1] = null; orderNumberArray[b - 1] = null; orderPriceArray[b - 1] = null; orderTimeArray[b - 1] = null; orderWayArray[b - 1] = null; orderDianzanArray[b - 1] = null; orderPhoneArray[b - 1] = null; orderManArray[b - 1] = null; System.out.println("订单删除成功"); break; case "5": //判断内容是否全部是 null 值,如果全部是 null 值,则表示没有商品,如果没有商品,后续的代码不再执行 int count1 = 0; for (int i = 0; i < orderNameArray.length; i++) { if (orderNameArray[i] == null) { count1++; } } //最后当 count == size 也就是20相等的话,表示全部是null if (count1 == size) { System.out.println("当前没有添加订单,请先添加订单"); break; } System.out.println("请输入要点赞的菜品序号:"); System.out.println("编号\t菜品名称\t菜品价格"); Scanner sca = new Scanner(System.in); int d = sca.nextInt(); int one = Integer.parseInt( orderDianzanArray[d-1]); orderDianzanArray[d-1]+=1; System.out.println("点赞成功"); break; case "6": default: System.out.println("程序退出"); isExit = true; break; } } }
}
运行结果:版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Zyw907155124/article/details/118913451
————————————————