• 吃货联盟订餐系统


    实现菜单切换:

    System.out.println("欢迎使用吃货联盟订单系统");
    Scanner input = new Scanner(System.in);
    int num=-1//用户输入0返回主菜单,否则退出系统;
    bolean isExit=false//标志用户是否退出系统;
    do{
    //显示菜单
    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.print("请选择:");
    int choose=input.nextInt();
     if(!isExit){
    System.out.print("输入0返回");
    num=input.nextInt();
    }else{
    break;
    }
    }while(num==0);

    定义一些变量:

            String[] cai = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };// 菜品
            String[] names = new String[4];// 订餐人
            int[] nums = new int[4];// 份数
            int[] time = new int[4];// 时间
            String[] site = new String[4];// 地址
            String[] state = new String[] { "预定", "预定", "预定", "预定" };// 订单状态
            double[] mond = { 38, 20, 10 };// 单价
            int a = -1;// 输入0返回
            int cd;// 输入菜单错误,重新选择
            double[] b = new double[4];// 总金额
            int[] zan = new int[3];// 点赞
            int i = 0;
            int e = 0;
            int qian;

    选择1:我要订餐

    case 1:
                    for (; i < names.length;) {
                        System.out.println("****我要订单****");
                        System.out.println("请输入订单人姓名:");//使用数组记录订单人名称
                        names[i] = bdqn.next();
                        do {
                            System.out.println("序号	" + "菜单	" + "单价" + "	点赞");
                            //利用for循环输出(序号-菜单-单价-点赞)
                            for (int j = 0; j < cai.length; j++) {
                                System.out.println((j + 1) + "	" + cai[j] + "	"
                                        + mond[j] + "	" + zan[j]);
                            }
                            System.out.println("请选择菜单:");
                            cd = bdqn.nextInt();
                            //判断输入的菜单数是否溢出菜单数
                            if (cd > 3 || cd < 1) {
                                System.out.println("没有此菜品!请重新选择:");
                            }
                        } while (cd > 3 || cd < 1);
                        System.out.println("送餐份数:");
                        nums[i] = bdqn.nextInt();
                        do {
                            System.out.println("请输入送餐时间(10至20点):");
                            time[i] = bdqn.nextInt();
                            //判断此时间营不营业
                            if (time[i] > 20 || time[i] < 10) {
                                System.out.println("此时间不营业!请重新输入:");
                            }
                        } while (time[i] > 20 || time[i] < 10);
                        System.out.println("请输入送餐地址:");
                        site[i] = bdqn.next();
                        System.out.println("成功预定!");
                        System.out.println("您订的是:" + cai[i] + nums[i]);
                        System.out.println("送餐时间:" + time[i]);
                        //定义一个变量用来储存送餐费,然后进行判断
                        double song = 0;
                        b[i] = mond[i] * nums[i] + song;
                        if (b[i] < 50) {
                            song = 5;
                        }
                        System.out.println("餐费:" + (b[i] - song) + "元,送餐费:" + song
                                + "元,总计:" + b[i]);
                        break;
                    }
                    //判断餐袋是否已满,未满再次执行时,录入第二次的订单情况
                    if (i >= site.length) {
                        System.out.println("餐袋已满!");
                    } else {
                        i++;
                    }
                    break;

    选择2:查看菜袋

        case 2:
                    System.out.println("****查看餐袋****");
                    System.out.println("序号	订餐人	餐品信息	送餐时间	送餐地址	总金额	订单状态");
                    //利用for循环输出(序号-订单人-餐品信息-送餐时间-送餐地址-总金额-订单状态)
                    for (int j = 0; j < i; j++) {
                        System.out.println((j + 1) + "	" + names[j] + "	"
                                + cai[j] + nums[j] + "份	" + time[j] + "	"
                                + site[j] + "	" + b[j] + "	" + state[j]);
                    }
                    break;

    选择3:签收订单

    case 3:
                    System.out.println("****签收订单****");
                    do {
                        System.out.println("请输入您要签收的订单:");
                        qian = bdqn.nextInt();
                        //输入要签收的订单,判断订单是否存在和是否已签收,若未签则执行签收
                        if (e == qian) {
                            System.out.println("订单已签收,不能再次签收!");
                        } else if (qian <= i) {
                            System.out.println("签收成功!");
                            state[qian - 1] = "签收";
                            e = qian;
                            break;
                        } else if (qian > i) {
                            System.out.println("没有该订单,请重新输入您要签收的订单:");
                        }
                    } while (qian > i);
                    break;

    选择4:删除订单

    case 4:
                    System.out.println("***删除订单****");
                    System.out.println("请输入您要删除的订单:");
                    int c = bdqn.nextInt();
                    //输入要删除的订单,并判断是否签收(只有签收成功,才能执行删除,删除时所有关于订餐情况下标-1)
                    if (c <= i) {
                        if (state[c - 1].equals("签收")) {
                            for (int j = c - 1; j < i; j++) {
                                if (j + 1 > 3) {// 预防数组溢出
                                    break;
                                }
                                names[j] = names[j + 1];
                                cai[j] = cai[j + 1];
                                nums[j] = nums[j + 1];
                                time[j] = time[j + 1];
                                site[j] = site[j + 1];
                                b[j] = b[j + 1];
                                state[j] = state[j + 1];
                            }
                            System.out.println("删除成功!");
                            i--;
                            e = 0;
                        } else {
                            System.out.println("您选择的订单,未签收,不能删除!");
                        }
                    } else {
                        System.out.println("没有此订单!");
                    }
                    break;

    选择5:我要点赞

    case 5:
                    System.out.println("****我要点赞****");
                    int l;
                    do {
                        System.out.println("请输入您要点赞的菜单:");
                        l = bdqn.nextInt();
                        switch (l) {// 每次选择点赞该商品+1
                        case 1:
                            zan[0]++;
                            System.out.println("点赞成功!");
                            break;
                        case 2:
                            zan[1]++;
                            System.out.println("点赞成功!");
                            break;
                        case 3:
                            zan[2]++;
                            System.out.println("点赞成功!");
                            break;
                        default:
                            System.out.println("无此商品序号!");
                            break;
                        }
                    } while (l > cai.length);
                    break;

    选择6:系统退出

    case 6:
                    System.out.println("退出系统!");
                    break;

    选择其他时,显示请重新输入:

    default:
                    System.out.println("您输入的数字没有相符合的系统,请重新选择:");
                    break;

    吃货联盟订餐系统:(整过程)

    import java.util.Scanner;
    
    public class Foodie {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Scanner bdqn = new Scanner(System.in);
            String[] cai = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };// 菜品
            String[] names = new String[4];// 订餐人
            int[] nums = new int[4];// 份数
            int[] time = new int[4];// 时间
            String[] site = new String[4];// 地址
            String[] state = new String[] { "预定", "预定", "预定", "预定" };// 订单状态
            double[] mond = { 38, 20, 10 };// 单价
            int a = -1;// 输入0返回
            int cd;// 输入菜单错误,重新选择
            double[] b = new double[4];// 总金额
            int[] zan = new int[3];// 点赞
            int i = 0;
            int e = 0;
            int qian;
            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("请选择:");
                int choose = bdqn.nextInt();
                switch (choose) {
                case 1:
                    for (; i < names.length;) {
                        System.out.println("****我要订单****");
                        System.out.println("请输入订单人姓名:");//使用数组记录订单人名称
                        names[i] = bdqn.next();
                        do {
                            System.out.println("序号	" + "菜单	" + "单价" + "	点赞");
                            //利用for循环输出(序号-菜单-单价-点赞)
                            for (int j = 0; j < cai.length; j++) {
                                System.out.println((j + 1) + "	" + cai[j] + "	"
                                        + mond[j] + "	" + zan[j]);
                            }
                            System.out.println("请选择菜单:");
                            cd = bdqn.nextInt();
                            //判断输入的菜单数是否溢出菜单数
                            if (cd > 3 || cd < 1) {
                                System.out.println("没有此菜品!请重新选择:");
                            }
                        } while (cd > 3 || cd < 1);
                        System.out.println("送餐份数:");
                        nums[i] = bdqn.nextInt();
                        do {
                            System.out.println("请输入送餐时间(10至20点):");
                            time[i] = bdqn.nextInt();
                            //判断此时间营不营业
                            if (time[i] > 20 || time[i] < 10) {
                                System.out.println("此时间不营业!请重新输入:");
                            }
                        } while (time[i] > 20 || time[i] < 10);
                        System.out.println("请输入送餐地址:");
                        site[i] = bdqn.next();
                        System.out.println("成功预定!");
                        System.out.println("您订的是:" + cai[i] + nums[i]);
                        System.out.println("送餐时间:" + time[i]);
                        //定义一个变量用来储存送餐费,然后进行判断
                        double song = 0;
                        b[i] = mond[i] * nums[i] + song;
                        if (b[i] < 50) {
                            song = 5;
                        }
                        System.out.println("餐费:" + (b[i] - song) + "元,送餐费:" + song
                                + "元,总计:" + b[i]);
                        break;
                    }
                    //判断餐袋是否已满,未满再次执行时,录入第二次的订单情况
                    if (i >= site.length) {
                        System.out.println("餐袋已满!");
                    } else {
                        i++;
                    }
                    break;
                case 2:
                    System.out.println("****查看餐袋****");
                    System.out.println("序号	订餐人	餐品信息	送餐时间	送餐地址	总金额	订单状态");
                    //利用for循环输出(序号-订单人-餐品信息-送餐时间-送餐地址-总金额-订单状态)
                    for (int j = 0; j < i; j++) {
                        System.out.println((j + 1) + "	" + names[j] + "	"
                                + cai[j] + nums[j] + "份	" + time[j] + "	"
                                + site[j] + "	" + b[j] + "	" + state[j]);
                    }
                    break;
                case 3:
                    System.out.println("****签收订单****");
                    do {
                        System.out.println("请输入您要签收的订单:");
                        qian = bdqn.nextInt();
                        //输入要签收的订单,判断订单是否存在和是否已签收,若未签则执行签收
                        if (e == qian) {
                            System.out.println("订单已签收,不能再次签收!");
                        } else if (qian <= i) {
                            System.out.println("签收成功!");
                            state[qian - 1] = "签收";
                            e = qian;
                            break;
                        } else if (qian > i) {
                            System.out.println("没有该订单,请重新输入您要签收的订单:");
                        }
                    } while (qian > i);
                    break;
                case 4:
                    System.out.println("***删除订单****");
                    System.out.println("请输入您要删除的订单:");
                    int c = bdqn.nextInt();
                    //输入要删除的订单,并判断是否签收(只有签收成功,才能执行删除,删除时所有关于订餐情况下标-1)
                    if (c <= i) {
                        if (state[c - 1].equals("签收")) {
                            for (int j = c - 1; j < i; j++) {
                                if (j + 1 > 3) {// 预防数组溢出
                                    break;
                                }
                                names[j] = names[j + 1];
                                cai[j] = cai[j + 1];
                                nums[j] = nums[j + 1];
                                time[j] = time[j + 1];
                                site[j] = site[j + 1];
                                b[j] = b[j + 1];
                                state[j] = state[j + 1];
                            }
                            System.out.println("删除成功!");
                            i--;
                            e = 0;
                        } else {
                            System.out.println("您选择的订单,未签收,不能删除!");
                        }
                    } else {
                        System.out.println("没有此订单!");
                    }
                    break;
                case 5:
                    System.out.println("****我要点赞****");
                    int l;
                    do {
                        System.out.println("请输入您要点赞的菜单:");
                        l = bdqn.nextInt();
                        switch (l) {// 每次选择点赞该商品+1
                        case 1:
                            zan[0]++;
                            System.out.println("点赞成功!");
                            break;
                        case 2:
                            zan[1]++;
                            System.out.println("点赞成功!");
                            break;
                        case 3:
                            zan[2]++;
                            System.out.println("点赞成功!");
                            break;
                        default:
                            System.out.println("无此商品序号!");
                            break;
                        }
                    } while (l > cai.length);
                    break;
                case 6:
                    System.out.println("退出系统!");
                    break;
                default:
                    System.out.println("您输入的数字没有相符合的系统,请重新选择:");
                    break;
    
                }
                if (choose == 6) {
                    break;
                }
                System.out.println("输入0返回:");
                a = bdqn.nextInt();
            } while (a == 0);
        }
    }

  • 相关阅读:
    引用的难点:函数返回值是引用(引用当左值)
    引用的意义与本质
    引用做函数参数
    Uva
    Uva
    Uva
    暑假集训-8.06总结
    暑假集训-8.05总结
    CH1801( 括号画家)
    最大异或对
  • 原文地址:https://www.cnblogs.com/fl72/p/7403713.html
Copyright © 2020-2023  润新知