Java练习小项目01

(数组)顾客点餐系统

import java.util.*;

public class XiangMu {
    public static void main(String[] args) {

        String[] name = new String[100];
        String[] caipin = new String[100];
        int[] sum = new int[100];
        String[] times = new String[100];
        String[] site = new String[100];
        double[] money = new double[100];
        int[] stste = new int[100];

        String[] menu = {"清蒸鱼","爆炒大虾","麻婆豆腐"};
        double[] price = {58.9,38.9,18.9};
        int[] like = new int[3];

        System.out.println("欢迎使用快跑订餐系统");

        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("请选择:");
            Scanner num = new Scanner(System.in);
            int m = num.nextInt();
            int count = 0;

            switch(m){
                case 1:
                    System.out.println("***我要订餐***");
                    System.out.println("请输入订餐人姓名:");
                    String  x1 = num.next();
                    for (int i = 0; i < 100; i++) {
                        if(name[i] == null) {
                            name[i] = x1;
                            break;
                        }
                    }
                    System.out.println("序号\t"+"菜名\t"+"单价\t");
                    for (int i = 0; i < like.length-1; i++) {
                        for (int k = 0; k < like.length-1-i; k++) {
                            if(like[k]<like[k+1]){
                                int n = like[k+1];
                                String n1 = menu[k+1];
                                double n2 = price[k+1];

                                like[k+1] = like[k];
                                menu[k+1] = menu[k];
                                price[k+1] = price[k];

                                like[k] = n;
                                menu[k] = n1;
                                price[k] = n2;

                            }
                        }
                    }
                    for (int j = 0; j < 3; j++) {
                        System.out.println((j+1)+"\t"+menu[j]+"  "+price[j]);
                    }


                    System.out.println("请选择您要点的菜品编号:");
                    int x2 = num.nextInt();
                    for (int i = 0; i < 100; i++) {
                        if(caipin[i] == null){
                            caipin[i] = menu[x2-1];
                            break;
                        }
                    }
                    System.out.println("请选择您需要的份数:");
                    int x3 = num.nextInt();
                    for (int i = 0; i < 100; i++) {
                        if(sum[i] == 0){
                            sum[i] = x3;
                            break;
                        }
                    }
                    System.out.println("请输入送餐时间:");
                    String x4 = num.next();
                    for (int i = 0; i < 100; i++) {
                        if(times[i] == null){
                            times[i] = x4;
                            break;
                        }
                    }
                    System.out.println("请输入送餐地址:");
                    String x5 = num.next();
                    for (int i = 0; i < 100; i++) {
                        if(site[i] == null){
                            site[i] = x5;
                            break;
                        }
                    }
                    for (int i = 0; i < 100; i++) {
                        if(money[i] == 0){
                            money[i] = price[x2-1]*sum[i];
                            System.out.println("订餐成功!");
                            System.out.println("您订的是:"+caipin[i]+" "+sum[i]+"份");
                            System.out.println("送餐时间:"+times[i]);
                            System.out.println("餐费:"+money[i]+"元"+"送餐费:0元"+"总计"+money[i]+"元");
//                            count = i;
//                            System.out.println(count);
                            break;
                        }
                    }

                    break;

                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序号\t"+"订餐人\t"+"餐品信息\t"+"送餐日期\t"+"送餐地址\t"+"总金额\t"+"订单状态\t");
                    for (int i = 0; i < 100; i++) {
                        if(name[i] == null){
                            count = i;
                            break;
                        }
                    }
                    for (int i = 0; i < count; i++) {
                        System.out.println((i+1)+" "+name[i]+" "+caipin[i]+sum[i]+"份"+" "+times[i]+" "+
                    site[i]+" "+money[i]+" "+(stste[i]==0?"已预订":"已完成"));
                    }
                    break;
                case 3:
                    System.out.println("***签收订单***");
                    System.out.println("请选择需要签收的订单序号:");
                    int x6 = num.nextInt();
                    stste[x6-1] = 1;
                    System.out.println("订单签收成功!");
                    break;
                case 4:
                    System.out.println("***删除订单***");
                    System.out.println("请输入需要删除的订单序号:");
                    int x7 = num.nextInt();
                    if(stste[x7-1] == 0){
                        System.out.println("您选择的订单未签收,不能删除!");
                    }else{
                        for (int i = x7-1; i < name.length; i++) {
                            if(name[i] == null){
                                break;
                            }else{
                                name[i] = name[i+1];
                                caipin[i] = caipin[i+1];
                                sum[i] = sum[i+1];
                                times[i] = times[i+1];
                                site[i] = site[i+1];
                                money[i] = money[i+1];
                                stste[i] = stste[i+1];
                            }
                        }
                        System.out.println("您选择的订单已成功删除!");
                    }
                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("请输入您要点赞的菜品序号:");
                    int y = num.nextInt();
                    like[y-1]++;
                    break;
                default:
                    System.out.println("祝您用餐愉快,欢迎下次光临!");
                    break;
            }
            if(m == 6){
                break;
            }else{
                System.out.println("输入0返回:");
                int n = num.nextInt();
            }
        }while(true);


    }
}

(集合)顾客点餐系统

import java.util.*;

public class XiangMu2 {
    public static void main(String[] args) {
        List<String> name = new ArrayList<>();
        List<String> caipin = new ArrayList<>();
        List<Integer> sum = new ArrayList<>();
        List<String> times = new ArrayList<>();
        List<String> site = new ArrayList<>();
        List<Double> money = new ArrayList<>();
        LinkedList<Integer> stste = new LinkedList<>();

        Map<Integer, String> menu = new HashMap<>();
//        LinkedList<String> menu = new LinkedList<>();
        menu.put(0,"清蒸魚");
        menu.put(1,"爆炒大虾");
        menu.put(2,"麻婆豆腐");
        Map<Integer, Double> price = new HashMap<>();
//        LinkedList<Double> price = new LinkedList<>();
        price.put(0,58.9);
        price.put(1,38.9);
        price.put(2,18.9);
        Map<Integer, Integer> like = new HashMap<>();

        System.out.println("欢迎使用快跑订餐系统");

        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("请选择:");
            Scanner num = new Scanner(System.in);
            int m = num.nextInt();
            int count = 0;

            switch(m){
                case 1:
                    System.out.println("***我要订餐***");
                    System.out.println("请输入订餐人姓名:");
                    name.add(num.next());

                    System.out.println("序号\t"+"菜名\t"+"单价\t");
                    for (int j = 0; j < 3; j++) {
                        System.out.println((j+1)+"\t"+menu.get(j)+"  "+price.get(j));
                    }

                    System.out.println("请选择您要点的菜品编号:");
                    int x2 = num.nextInt()-1;
                    caipin.add(menu.get(x2));

                    System.out.println("请选择您需要的份数:");
                    int x3 = num.nextInt();
                    sum.add(x3);

                    System.out.println("请输入送餐时间:");
                    String x4 = num.next();
                    times.add(x4);

                    System.out.println("请输入送餐地址:");
                    String x5 = num.next();
                    site.add(x5);

                    money.add((price.get(x2) * x3));

                    System.out.println("订餐成功!");
                    System.out.println("您订的是:"+menu.get(x2)+" "+x3+"份");
                    System.out.println("送餐时间:"+x4);
                    System.out.println("餐费:"+(price.get(x2) * x3)+"元"+"送餐费:0元"+"总计"+(price.get(x2) * x3)+"元");

                    stste.add(0);

                    break;

                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序号\t"+"订餐人\t"+"餐品信息\t"+"送餐日期\t"+"送餐地址\t"+"总金额\t"+"订单状态\t");
                    for (int i = 0; i < name.size(); i++) {
                        System.out.println((i+1)+" "+name.get(i)+" "+caipin.get(i)+" "+times.get(i)+" "+
                                site.get(i)+" "+money.get(i)+" "+((stste.get(i) == 0)?"已预订":"已完成"));
                    }

                    break;
                case 3:
                    System.out.println("***签收订单***");
                    System.out.println("请选择需要签收的订单序号:");
                    int x6 = num.nextInt()-1;
                    stste.remove(x6);
                    stste.add(x6,1);
                    System.out.println("订单签收成功!");
                    break;
                case 4:
                    System.out.println("***删除订单***");
                    System.out.println("请输入需要删除的订单序号:");
                    int x7 = num.nextInt()-1;
                    if(stste.get(x7) == 0){
                        System.out.println("您选择的订单未签收,不能删除!");
                    }else{
                        if(x7 < name.size()){
                            name.remove(x7);
                            caipin.remove(x7);
                            sum.remove(x7);
                            times.remove(x7);
                            site.remove(x7);
                            money.remove(x7);
                            stste.remove(x7);

                            System.out.println("您选择的订单已成功删除!");
                        }

                    }



                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("请输入您要点赞的菜品序号:");
                    int y = num.nextInt();
                    int y1 = like.get(y);
                    like.put(y,y1+1);

                    break;
                default:
                    System.out.println("祝您用餐愉快,欢迎下次光临!");
                    break;
            }
            if(m == 6){
                break;
            }else{
                System.out.println("输入0返回:");
                int n = num.nextInt();
            }
        }while(true);

    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值