• 吃货联盟


    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("
    欢迎使用“吃货联盟订餐系统”");
    
            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("序号" + "	" + "菜名" + "	" + "单价"
                                    + "	" + "点赞数");
                    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) + "	" + dishNames[i]
                                    + "	" + price + "	" + 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("序号	订餐人	餐品信息		送餐日期	送餐地址		总金额	订单状态");
                    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) + "	" + names[i] + "	"
                            + dishMegs[i] + "	" + day + "	"
                            + addresses[i] + "	" + sumPrice1 + "	"
                            + 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("序号" + "	" + "菜名" + "	" + "单价" + "	");
                    for (int i = 0; i < dishNames.length; i++) {
                    String price = prices[i] + "";
                        
                    String priaiseNum = (praiseNums[i]) > 0 ? praiseNums[i]
                                + "" : "";
                    System.out.println((i + 1) + "	" + dishNames[i] + "	"
                                + price + "	" + 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("退出系统,谢谢使用!");
        }
    }
  • 相关阅读:
    jQuery属性操作,attr 和 prop的区别。笔记记录
    li 自身样式不显示?使用 overflow:hidden 导致li 前面点,圈等样式不见情况处理
    jQuery 最新版类库 和 常用的类库[jquery-1.12.3,jquery-1.7.2]下载
    Excel 中如何让下拉菜单显示汉字,但是值是数字
    Uncaught TypeError: $(...).on is not a function
    全选,全不选,反选的逻辑思路
    Linux 解决 vsftpd 读取目录列表失败的问题。
    SQL Sever 2012数据库从下载到安装完成【一步一图,带上脑子即可】
    【闲暇研究】某问道,游戏的整合记录
    Tomcat 启动后出现乱码的解决办法。
  • 原文地址:https://www.cnblogs.com/864466244qq/p/7411356.html
Copyright © 2020-2023  润新知