zoukankan      html  css  js  c++  java
  • Java——吃货联盟订餐系统

    public static void main(String[] args) {
            
            String[] names = new String[4];  //订餐人姓名
            String[] dishMegs = new String[4];  //保存菜品名及份数
            int[] times =new int[4];  //送餐时间
            String[] addresses = new String[4];  //保存送餐地址
            int[] states = new int[4];    //保存订单状态: 0表示已预订,1表示已完成
            double[] sumPrices = new double[4];   //保存订单的总金额
            
            //初识化订单信息
            names[0]="张青";
            dishMegs[0]="红烧带鱼 2份";
            times[0]=12;
            addresses[0]="天成路207号";
            states[0]=1;
            sumPrices[0]=76.0;
            
            names[1]="张青";
            dishMegs[1]="鱼香肉丝 2份";
            times[1]=18;
            addresses[1]="天成路207号";
            states[1]=0;
            sumPrices[1]=45.0;
            
            String[] dishNames ={"红烧带鱼","鱼香肉丝","时冷鲜疏"};  //菜单
            double[] prices ={38.0,20.0,10.0};       //价格 
            int[] praiseNums =new int[]{58,45,50};   //点赞数
            
            Scanner input = new Scanner(System.in);
            int num=-1;      //用户输入0返回菜单,否则退出
            boolean isExit=false;  //标志用户是否退出系统;true 为退出系统
            
            System.out.println("	欢迎使用“吃货联盟订餐系统”");
            auter:
            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("请选择:");
                int choose = input.nextInt();
                switch(choose){
                    case 1:
                        System.out.println("***我要订餐***");
                        System.out.println("请输入订餐人姓名:");
                        String name=input.next();
                        
                        boolean isAdd = false; //记录是否可以订餐
                        for (int i = 0; i < names.length; i++) {
                            if(names[i]==null){
                                isAdd = true;
                                System.out.println("序号	菜品名称	菜品单价	点赞数");
                                
                                for (int j = 0; j < dishNames.length; j++) {
                                    System.out.println((j+1)+"	"+dishNames[j]+"	 "+prices[j]+"	 "+praiseNums[j]);
                                }
                                
                                System.out.println("请选择您要点的菜品编号:");
                                int chooseDich = input.nextInt();
                                System.out.println("请选择您需要的份数:");
                                int number = input.nextInt();
                                
                                //得到订餐信息
                                String dishMeg=dishNames[chooseDich-1]+" "+number+"";  
                                //订餐总金额
                                double sumPrice = prices[chooseDich-1] *number;
                                //订餐满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 address = input.next();
                                //无需添加状态,默认为0
                                System.out.println("订餐成功!");
                                
                                System.out.println("您定的是:"+dishMeg);
                                System.out.println("送餐时间:"+time);
                                System.out.println("餐费:"+sumPrice+"元,送餐费"+deliCharge+"元,总计:"+(sumPrice+deliCharge)+"");
                                System.out.println();
                                //添加数据
                                names[i]=name;
                                dishMegs[i]=dishMeg;
                                times[i]=time;
                                addresses[i]=address;
                                sumPrices[i]=sumPrice+deliCharge;
                                break;
                            }
                        }
                        
                        if(!isAdd){   //
                            System.out.println("对不起,您的餐袋已满!");
                        }
                        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)?"已预订":"已完成";
                                    
                                System.out.println((i+1)+"	"+names[i]+"	"+dishMegs[i]+"	"+times[i]+"	"+addresses[i]+"	"+sumPrices[i]+"	"+state);
                            }
                        }
                        
                        break;
                    case 3:
                        System.out.println("***签收订单***");
                        System.out.println("签收订单的序号:");
                        int delId=input.nextInt();
                        boolean isSignFind = false;
                        for (int i = 0; i < names.length; i++) {
                            if(names[i]!=null && i ==(delId-1) && states[i]==0){
                                states[i]=1;   //状态改为 1
                                System.out.println("订单签收成功");
                                isSignFind=true;
                                break;
                            }else if(names[i]!=null && i ==(delId-1) && states[i]==1){
                                System.out.println("您选择的订单已完成签收,不能再次签收!");
                                isSignFind=true;
                            }
                        }
                        if(!isSignFind){   
                            System.out.println("您选择的订单不存在!");
                        }
                        break;
                    case 4:
                        System.out.println("***删除订单***");
                        System.out.println("输入要删除的订单编号:");
                        int dinId=input.nextInt();
                        boolean isDelFind=false;
                        for (int i = 0; i < names.length; i++) {
                            if(names[i]!=null && states[i]==1 && i==(dinId-1)){
                                isDelFind=true;
                                for (int j = i; 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 && i==(dinId-1)){
                                System.out.println("您选择的订单未签收,不能删除!");
                                isDelFind =true;
                                break;
                            }
                        }
                        
                        if(!isDelFind){
                            System.out.println("您要删除的订单不存在!");
                        }
                        break;
                    case 5:
                        System.out.println("***我要点赞*** ");
                        System.out.println("序号	菜品名称	菜品单价	点赞数");
                        
                        for (int j = 0; j < dishNames.length; j++) {
                            System.out.println((j+1)+"	"+dishNames[j]+"	 "+prices[j]+"	 "+praiseNums[j]);
                        }
                        System.out.println("请输入您要点赞的菜品序号:");
                        int priaiseNum = input.nextInt();
                        praiseNums[priaiseNum-1]+=1;
                        System.out.println("点赞成功!");
                        break;
                    case 6:
                        System.out.println("退出系统!");
                        break auter;
                    default:
                        isExit=true;
                        break;
                }
                
                if(!isExit){
                    System.out.println("输入0返回");
                    num=input.nextInt();
                }
                
            }while(num==0);
            System.out.println("欢迎使用订餐系统");
        }
  • 相关阅读:
    IE11 for Windows 7 Enterprise With SP1 故障
    UE4 中的人工智能解析—ShooterGame为例
    人类探索地外文明取得的重大进步
    物理读之LRU(近期最少被使用)的深入解析
    iOS开发
    VS2008 集成Lua解释器
    android studio下载地址
    UVA 11235 Frequent values (RMQ)
    又见关系并查集 以POJ 1182 食物链为例
    Android蓝牙技术Bluetooth使用流程(具体解释)
  • 原文地址:https://www.cnblogs.com/szj-ang/p/7281895.html
Copyright © 2011-2022 走看看