• 吃货联盟代码


     订餐项目改于2020-09-17

     1.数据初始化。

    public class chu{
        //name=菜名
        String[] name = new String[4];
        //dishMegs=菜品及份数
        String[] dishMegs = new String[4];
        //times=送餐时间
        int[] times = new int[4];
        //addresses=送餐地址
        String[] addresses = new String[4];
        //states=订单状态
        int[] states = new int[4];
        //titals=花费的总金额
        double[] totals = new double[4];
        //实现订餐功能
        boolean a;
    }

     2.功能编写

    import java.util.Scanner;
    
    public class first {
        Scanner input = new Scanner(System.in);
        //menu=菜名
        String[] menu = {"红烧带鱼", "鱼香肉丝", "时令蔬菜"};
        //count=菜品单价
        double[] counts = {38.0, 20.0, 10.0};
        //zan=点赞数
        int[] zans = new int[3];
        chu check=new chu();
        //实现我要订餐
        public boolean add() {
            boolean isAdd = false;
            for (int j = 0; j < check.name.length; j++) {
                if (check.name[j] == null) {
                    isAdd = true;
                    System.out.println("请输入订餐人的姓名:");
                    while (input.hasNextInt()){
                        System.out.println("请输入正确的名字:");
                        int name=input.nextInt();
                    }
                    //name=订餐人的姓名
                    String name = input.next();
                    System.out.println("序号			菜名			单价			点赞数");
                    for (int i = 0; i < menu.length; i++) {
                        String count = counts[i] + "元";
                        String zan = (zans[i]) > 0 ? zans[i] + "	" + "赞" : "0";
                        System.out.println((i + 1) + "			" + menu[i] + "		" + count + "			" + zan);
                    }
                    System.out.println("请选择您要点的菜品编号:");
                    while (!input.hasNextInt()){
                        System.out.println("请输入正确的数字:");
                        String gun=input.next();
                    }
                    //choose=要点的菜品编号
                    int choose = input.nextInt();
                    while (choose < 0 || choose > 3) {
                        System.out.println("输入错误,请输入1至3之间的数");
                        choose = input.nextInt();
                    }
                    System.out.println("请选择您需要的份数(餐费超过50元会免费配送的哟!):");
                    while (!input.hasNextInt()){
                        System.out.println("请输入正确的数字(餐费超过50元会免费配送的哟!):");
                        String number=input.next();
                    }
                    //fen=菜品的份数
                    int fen = input.nextInt();
                    if (0>fen||fen>200){
                        System.out.println("对不起,我们没有那么多原材料,请重新预订:");
                        add();
                    }
                    String dishMeg = menu[choose - 1] + "" + fen + "份";
                    double sum = counts[choose - 1] * fen;
                    //deliCharge=送餐费,如果没够50加付5元,满足50或超过50则不需要付送餐费
                    double deliCharge = (sum >= 50) ? 0 : 5;
                    double total = sum + deliCharge;
                    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 address = input.next();
                    String regex = "[u4E00-u9FA5]+";
                    while (!(address.matches(regex))){
                        System.out.println("请输入正确的地址:");
                        address=input.next();
                    }
                    System.out.println("订餐成功!");
                    System.out.println("您订的是:" + dishMeg);
                    System.out.println("送餐时间:" + time+"点");
                    System.out.println("餐费:" + sum + "元,送餐费" + deliCharge + "元,总计:" + total + "元");
                    check.name[j] = name;
                    check.dishMegs[j] = dishMeg;
                    check.times[j] = time;
                    check.addresses[j] = address;
                    check.totals[j] = total;
                    break;
                }
            }
            if (!isAdd) {
                System.out.println("对不起,您的订单已满!");
                return isAdd;
            } else {
                return isAdd;
            }
        }
        //实现查看餐袋
        public void checks() {
            System.out.println("序号		订餐人姓名	餐品信息			送餐时间		送餐地址		总金额		订单状态");
            for (int i = 0; i < check.name.length; i++) {
                if (check.name[i]!=null){
                    String state = (check.states[i] == 0) ? "已预定" : "已完成";
                    String date = check.times[i] + "点";
                    String total = check.totals[i] + "元";
                    System.out.println((i + 1) + "		" + check.name[i] + "   		" + check.dishMegs[i] + "		" + date + "			" + check.addresses[i] + "  		" + total + "		" + state);
                }
            }
        }
        //实现签收订单
        public void sign(){
            boolean isBig=false;
            System.out.println("请选择要签收的订单编号:");
            while (!(input.hasNextInt())){
                System.out.println("请输入正确的数字:");
                String digit = input.next();
            }
            int number=input.nextInt();
            for (int i=0;i<check.name.length;i++){
                if (check.name[i]!=null&&check.states[i]==0&&number==i+1){
                    check.states[i]=1;
                    System.out.println("订单签收成功!");
                    isBig=true;
                }else if (check.name[i]!=null&&check.states[i]==1&&number==i+1){
                    System.out.println("您选择的菜单已完成签收,不能再次签收!");
                    isBig=true;
                }
            }
            if (!isBig){
                System.out.println("您选择的订单不存在!");
            }
        }
        //实现删除订单
        public void delete(){
            boolean isSmall=false;
            System.out.println("请输入要删除的订单编号:");
            while (!(input.hasNextInt())){
                System.out.println("请输入数字:");
                String figure=input.next();
            }
                int nums=input.nextInt();
            for (int i=0;i<check.name.length;i++){
                if (check.name[i]!=null&&check.states[i]==1&&nums==i+1){
                    isSmall=true;
                    for (int j=nums-1;j<check.name.length-1;j++){
                        check.name[j]=check.name[j+1];
                        check.dishMegs[j]=check.dishMegs[j+1];
                        check.times[j]=check.times[j+1];
                        check.addresses[j]=check.addresses[j+1];
                        check.states[j]=check.states[j+1];
                        check.totals[j]=check.totals[j+1];
                    }
                    int endIndex=check.name.length-1;
                    check.name[endIndex]=null;
                    check.dishMegs[endIndex]=null;
                    check.times[endIndex]=0;
                    check.addresses[endIndex]=null;
                    check.states[endIndex]=0;
                    check.totals[endIndex]=0;
                    System.out.println("删除订单成功!");
                    break;
                }else if (check.name[i]!=null&&check.states[i]==0&&nums==i+1){
                    System.out.println("您选择的订单未签收,不能删除!");
                    isSmall=true;
                    break;
                }
            }
            if (!isSmall){
                System.out.println("您要删除的订单不存在!");
            }
        }
        //实现点赞功能
        public void praise(){
            System.out.println("序号"+"	"+"菜名"+"	"+"单价");
            for (int i=0;i<menu.length;i++){
                String price=counts[i]+"元";
                String priceNum=(zans[i])>0?zans[i]+"赞":"";
                System.out.println((i+1)+"	"+menu[i]+"	"+price+"	"+priceNum);
            }
            System.out.println("请选择您要点赞的菜品序号:");
            while (!(input.hasNextInt())){
                System.out.println("请输入正确的数字:");
                String digitial=input.next();
            }
            int praiseNum=input.nextInt();
            if (praiseNum>=3){
                int num;
                do {
                    System.out.println("对不起,输入不符合规范请重新输入:");
                     num=input.nextInt();
                }while (num>3);
    
            }else {
                zans[praiseNum-1]++;
                System.out.println("点赞成功!");
            }
        }
        //实现满意程度调查
        public void satisfaction(){
            System.out.println("满意程度:");
            while (!input.hasNextInt()){
                System.out.println("请输入1到3的数字哦!");
                String num=input.next();
            }
            int du=input.nextInt();
            switch (du){
                case 1:
                    System.out.println("不满意");
                    System.out.println("对不起,给亲带来了不便请见谅!我们还会继续努力的(≖ᴗ≖)✧");
                    break;
                case 2:
                    System.out.println("还行吧");
                    System.out.println("谢谢亲的评价!(๑*◡*๑)");
                    break;
                case 3:
                    System.out.println("非常满意");
                    System.out.println("感谢亲的好评,我们会继续努力的!ヾ(^Д^*)/");
                    break;
                default:
                    System.out.print("您的输入不符合规范哦!");
                    satisfaction();
            }
        }
        //实现幸运免单
        public void lucky(){
            System.out.println("欢迎参与我们的幸运免单,你会是那个幸运的人吗?");
            System.out.println("请随机选取一个“四位数”哦:");
            while (!input.hasNextInt()){
                System.out.println("请输入正确的四位数哦:");
                String digit=input.next();
            }
            int num=input.nextInt();
            int max=9999;
            int min=1000;
            int cardNumber=(int)(Math.random()*(max-min)+min);
            if (!(num==cardNumber)){
                System.out.println("对不起,亲不是我们的幸运用户哦!");
            }else {
                System.out.println("恭喜亲成功免单!(◕ᴗ◕✿)");
            }
        }
    }

    3.测试类。

    
    
    import java.util.Scanner;
    
    public class eating {
        public static void main(String[] args) {
            boolean isBig=false;
            int bum;
            boolean a=false;
            first check=new first();
            do {
                System.out.println("欢迎使用“吃货联盟订餐系统”");
                System.out.println("*******************************************************");
                System.out.println("1.我要订餐
    2.查看餐袋
    3.签收订单
    4.删除订单
    5.幸运免单
    6.我要点赞
    7.满意程度
    8.退出系统");
                System.out.println("********************************************************");
                System.out.println("请选择:");
                Scanner input=new Scanner(System.in);
                while (!input.hasNextInt()){
                    System.out.println("输入有误,请重新输入:");
                    String xum=input.next();
                }
                int num=input.nextInt();
                switch (num){
                    case 1:
                        System.out.println("****我要订餐****");
                        a=check.add();
                        break;
                    case 2:
                        System.out.println("****查看餐袋****");
                        if (a) {
                            check.checks();
                        }
                        break;
                    case 3:
                        System.out.println("****签收订单****");
                        check.sign();
                        break;
                    case 4:
                        System.out.println("****删除订单****");
                        check.delete();
                        break;
                    case 5:
                        System.out.println("****幸运免单****");
                        if (a) {
                            check.lucky();
                        }else {
                            System.out.println("您没有参与活动的权限,请先订单!");
                        }
                        break;
                    case 6:
                        System.out.println("****我要点赞****");
                        check.praise();
                        break;
                    case 7:
                        System.out.println("1.不满意
    2.还行吧
    3.非常满意");
                        check.satisfaction();
                        break;
                    case 8:
                        isBig=true;
                        break;
                    default:
                        System.out.print("输入有误!");
    
                }
                if (!isBig){
                    System.out.println("按0返回系统(其他均退出系统):");
                    bum=input.nextInt();
                }else {
                    break;
                }
            }while (bum==0);
            System.out.println("谢谢使用,欢迎下次光临!");
        }
    }

    自己做的一个小项目,总之还是挺满意的。

  • 相关阅读:
    Visual Studio调试提示未能找到路径 bin oslyncsc.exe
    泛型
    Java中System.setProperty()
    jQuery的基础·知识
    移动端事件与touch.js库(js)
    js中,求1~100之间的质数
    匿名函数,闭包与ajax(js)
    正则(js)
    面向对象的概念,创建,实例,call与apply,继承(js)
    事件基础,事件绑定,DOM事件流与事件的默认行为,键盘事件,滚轮事件,事件委托(js)
  • 原文地址:https://www.cnblogs.com/lyy2993945268/p/11948899.html
Copyright © 2020-2023  润新知