JAVA学习日记12.27——订餐系统

package cn.kgc;

import sun.security.x509.SubjectAlternativeNameExtension;

import java.util.Scanner;

/**
 * @Author $(USER)
 * @Date $(DATE)
 * @Description 吃货联盟订餐系统
 */
public class chihuolianmeng {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] dishes={"鸡丁","菜1","菜2","菜3","菜4"};
        double[] prices={23,52,48,54,85};
        int[] honor=new int[5];
        final double sendprice=6;
        String[][] orders=new String[1000][];
        System.out.println("*********欢迎使用吃货联盟订餐系统**********");
        int choice;
        do{
            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("请输入你的选择:");
            choice=sc.nextInt();
            switch(choice){
                case 1://订餐
                System.out.println("请输入您的姓名:");
                String name=sc.next();
                //展示菜单
                System.out.println("序号\t菜名\t价格\t点赞");
                for(int i=0;i<dishes.length;i++){
                    System.out.println(i+1+"\t"+dishes[i]+"\t"+prices[i]+"\t"+honor[i]);
                }
                System.out.println("请输入您要点的菜品:");
                int num=sc.nextInt();
                System.out.println("请输入份数:");
                int fenshu=sc.nextInt();
                System.out.println("请输入送餐时间(8:00-20:00):");
                double time=sc.nextDouble();
                System.out.println("请输入送餐地址:");
                String address=sc.next();
                double total=prices[num-1]*fenshu;
                total=total>60?total:total+sendprice;
                    System.out.println(name+"顾客,恭喜您订餐成功,您点了"+dishes[num- 
                                      1]+fenshu+"份"+
                            "总价为:"+total+"\t"+time+"点送达,您的地址为"+address);
                    for (int i = 0; i < orders.length; i++) {
                        if(orders[i]==null){
                            orders[i]=new String[]{dishes[num-1]+"\t" +fenshu+"\t"
                            +total+"\t"+time+"点\t"+address,"已预定"};
                            break;
                        }
                    }
                    break;
                case 2://查看订单
                    System.out.println("***查看订单***");
                    System.out.println("序号\t菜名\t份数\t总价\t姓名\t时间\t地址\t状态\t");
                    for(int i=0;i<orders.length;i++){
                        if(orders[i]==null){
                            break;
                        }
                        System.out.println(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]);

                    }
                    break;
                case 3://确认订单
                    System.out.println("请选择要确认的订单编号:");
                    int ordersnum=sc.nextInt();
                    if(orders[ordersnum-1]==null){
                        System.out.println("订单不存在!");
                    }
                    else if(orders[ordersnum-1][1].equals("已完成")){
                        System.out.println("订单已完成!请勿重复确认");
                    }else{
                        orders[ordersnum-1][1]="已完成";
                        System.out.println("订单确认成功!");
                    }
                   break;
                case 4://删除订单
                    System.out.println("***删除订单***");
                    System.out.println("序号\t菜名\t\t份数\t总价\t姓名\t时间\t地址\t状态 
                                      \t");
                    for(int i=0;i<orders.length;i++){
                        if(orders[i]==null){
                            break;
                        }
                        System.out.println(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]);
                    }
                    System.out.print("请输入要删除的订单:");
                    int delord=sc.nextInt();
                    if(orders[delord-1]==null){
                        System.out.println("订单不存在,删除失败!");
                    }else if(orders[delord-1][1].equals("已预定")){
                        System.out.println("订单未完成,不能删除!");
                    }else{
                        for(int i=delord-1;i<orders.length;i++){
                            orders[i]=orders[i+1];
                            if(orders[i+1]==null){
                                break;
                            }
                        }
                        System.out.println("删除成功!");
                    }
                    break;
                case 5://菜品点赞
                    System.out.println("序号\t菜名\t价格\t点赞");
                    for(int i=0;i<dishes.length;i++){
                        
                   System.out.println(i+1+"\t"+dishes[i]+"\t"+prices[i]+"\t"+honor[i]);
                    }
                    System.out.println("请输入点赞的菜品:");
                    int honornum=sc.nextInt();
                    honor[honornum-1]++;
                    break;
                case 6:
                break;
                default:
            }
        }while(choice>0&&choice<6);
        System.out.println("欢迎下次光临");




    }
}

猜你喜欢

转载自blog.csdn.net/kkkyzp/article/details/120999097