适合初学者练习的吃货联盟订单系统Java代码

package chihuo;

import java.util.Scanner;

public class OrderingUzi {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String[]disName={"红烧带鱼","鱼香肉丝","时令鲜蔬"};
        double[]prices=new double[]{38.0,20.0,10.0};
        int[]praiseNumes=new int[3];
        String[]name=new String[4];    //订餐人名称
        String[]dishMegs=new String[4];    //保存所选信息,包括菜品名及份数
        int[]times=new int[4];    //保存送餐时间
        int[]disNums=new int[4];//保存份数
        String[]addresses=new String[4];    //保存送餐地址
        int[]states=new int[4];    //保存订单状态:0表示已订预1表示已完成
        double[]money=new double[4];    //保存订单的总金额
        {
            name[0]="张倩";
            dishMegs[0]="红烧带鱼两份";
            disNums[0] = 2;
            times[0]=12;
            addresses[0]="天成路207号";
            states[0]=1;
            money[0]=76.0;
            
            name[1]="张倩";
            dishMegs[1]="红烧带鱼两份";
            disNums[0] = 2;
            times[1]=10;
            addresses[1]="天成路207号";
            states[1]=0;
            money[1]=45.0;
        }
        System.out.println("欢迎使用吃货联盟订单系统");
        int num=1;
        boolean exit=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.println("请选择");
            num=input.nextInt();
            /**
             * 开始
             */
            switch (num) {
            case 1:
                System.out.println("***我要订餐***");
                boolean ding=false;
                for (int i = 0; i < name.length; i++) {
                    if(name[i]==null){
                        ding=false;
                        System.out.println("请输入订餐人姓名");
                        String names=input.next();
                        System.out.println("序号"+"\t"+"菜名"+"\t"+"单价");
                        for (int j = 0; j < disName.length; j++) {
                            System.out.println((j+1)+"\t"+disName[j]+"\t"+prices[j]+"元"+"\t");
                        }
                        System.out.println("请选择您要的菜品编号");
                        int bian=input.nextInt();
                        String hao=disName[bian-1];
                        System.out.println("请选择您需要的份数");
                        int fen=input.nextInt();
                        System.out.println("请输入送餐时间(时间必须是10点至20点整点之间送餐)");
                        int time=input.nextInt();
                        while (time<10||time>20) {
                            System.out.println("您的输入有错,请输入正确时间");
                            time=input.nextInt();
                        }
                        System.out.println("请输入送餐地址");
                        String dizhi=input.next();
                        System.out.println("订餐成功");
                        System.out.println("您定的是"+disName[bian-1]+fen+"份");
                        System.out.println("送餐时间"+time+"点");
                        double sumprice=prices[bian-1]*fen;
                        double sendMoney=(sumprice>=50)?0:5;
                        System.out.println("餐费"+sumprice+"元"+"送餐费"+sendMoney+"元"+"总计"+(sumprice+sendMoney)+"元");
                        name[i]=names;
                        dishMegs[i] = hao;
                        times[i] = time;
                        disNums[i] = fen;
                        addresses[i] = dizhi;
                        prices[i] = sumprice + sendMoney;
                        break;
                    }
                    if(ding){
                        System.out.println("对不起您的参袋已满");
                    }
                }
                break;

            case 2:
                System.out.println("***查看参袋***");
                System.out.println("序号\t订餐人\t餐品名称\t\t餐品数量\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
                for (int i = 0; i < name.length; i++) {
                    if(name[i]!=null){
                        String state=(states[i]==0)?"已预订":"已成功";
                        System.out.println((i+1)+"\t"+name[i]+"\t"+dishMegs[i]+"\t"+disNums[i]+"份"+"\t\t"+times[i]+"\t\t"+addresses[i]+"\t"+prices[i]+"元"+"\t\t"+state);
                    }
                }
                break;
            case 3:
                System.out.println("***签收订单***");
                boolean qian=false;
                System.out.println("请选择要签收的订单序号");
                int xu=input.nextInt();
                for (int i = 0; i < name.length; i++) {
                    if(name[i]!=null&&states[i]==0&&xu==i+1){
                        states[i]=1;
                        System.out.println("订单签收成功");
                        qian=true;
                    }else if(name[i]!=null&&states[i]==1&&xu==i+1){
                        System.out.println("你选择的订单已完成签收,不能再次签收!");
                        qian=true;
                    }
                }
                if(!qian){
                    System.out.println("您选择的订单不存在");
                }
                break;
            case 4:
                System.out.println("***删除订单***");
                boolean shan=false;
                System.out.println("请输入要删除的订单序号");
                int hao=input.nextInt();
                for (int i = 0; i < name.length; i++) {
                    if(name[i]!=null&&states[i]==1&&hao==i+1){
                    shan=true;
                    for (int j = hao-1; j < name.length-1; j++) {
                        name[j]=name[j+1];
                        dishMegs[j]=dishMegs[j+1];
                        times[j]= times[j+1];
                        addresses[j]=addresses[j+1];
                        disNums[j]= disNums[j+1];
                        states[j]=states[j+1];
                        money[j]=money[j+1];
                    }
                    name[name.length-1]=null;
                    dishMegs[name.length-1]=null;
                    disNums[name.length-1]=0;
                    times[name.length-1]=0;
                    addresses[name.length-1]=null;
                    states[name.length-1]=0;
                    money[name.length-1]=0;
                    System.out.println("删除订单成功");
                    break;
                }else if(name[i]!=null&&states[i]==0&&hao==i+1){
                    shan=true;
                    System.out.println("你选择的订单未收签,不能删除");
                    break;
                }
                }
                if(!shan){
                    System.out.println("您要的删的订单不存在");
                }
                break;
            case 5:
                System.out.println("***我要点赞***");
                System.out.println("序号\t菜名\t单价");
                for (int i = 0; i < disName.length; i++) {
                
                String praiseNume=(praiseNumes[i]>0)?praiseNumes[i]+"赞":"";
                System.out.println((i+1)+"\t"+disName[i]+"\t"+prices[i]+"元"+praiseNume);
                }
                System.out.println("请选择你要点赞的菜品序号");
                int cai=input.nextInt();
                praiseNumes[cai-1]++;
                System.out.println("点赞成功");
                break;
            case 6:
                System.out.println("***退出系统***");
                exit=true;
                break;
            default:
                exit=true;
                break;
            }
            if(!exit){
                System.out.println("输入0返回");
                num=input.nextInt();
            }else{
                break;
            }
        } while (num==0);
        System.out.println("谢谢使用欢迎下次光临");
        input.close();
    }

}

 

posted @ 2021-04-30 16:55  小吉米  阅读(431)  评论(0编辑  收藏  举报