吃货联盟项目

package OrderingMar;

import java.util.Scanner;

public class OrderingMar {

    Scanner input = new Scanner(System.in);

    String[] names = new String[4]; // 储存名字的数组

    String[] dismegs = new String[4]; // 商品信息

    int[] time = new int[4]; // 时间

    String[] addresses = new String[4]; // 地址

    int states[] = new int[4]; // 保存订单状态:0表示

    double[] sumprice = new double[4]; // 总金额

    String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令蔬菜" }; // 初始化菜单

    int[] distime = new int[] { 0, 0, 0, 0 }; // 初始化时间

    double[] prices = new double[] { 38.0, 20.0, 10.0 }; // 初始化价格

    int[] praiseNums = new int[] { 0, 0, 0 }; //
    int[] praiseNum = new int[3];
    int coose; // 选择对应功能

    boolean isExit = false; // 标志用户是否退出系统,true是退出系统

    int num = -1; // 用户输入0返回主菜单,否则退出系统;

    public void showone() {
        do {
            System.out.println("欢迎使用吃货联盟订餐系统");
            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("请选择");
            coose = input.nextInt(); // 选择对应功能

            switch (coose) {
            case 1:
                for (int i = 0; i < names.length; i++) {
                    if (names[i] == null) {
                        System.out.println("请输入订餐人姓名");
                        String name = input.next();
                        System.out.println();
                        System.out.println("序号\t菜名\t单价\t点赞数");
                        for (int j = 0; j < dishNames.length; j++) {

                            
                            System.out.println((j + 1) + "\t" + dishNames[j]
                                    + "\t" + prices[j] + "\t" + praiseNum[j]);
                        }
                        System.out.println("请选择你要点的菜品编号");
                        int num = input.nextInt();
                        System.out.println("请输入你需要的份数");
                        int number = input.nextInt();
                        String dismegs = dishNames[num - 1] + "" + number + "份";
                        double sumprices = prices[num - 1] * number;

                        double deilcharge = (sumprices >= 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();
                        System.out.println("订餐成功");
                        System.out.println("你定的餐是" + dismegs);
                        System.out.println("送餐时间" + time);
                        System.out.println("餐费" + sumprices + "元" + "送餐费"
                                + deilcharge + "元" + "总计"
                                + (sumprices + deilcharge));

                        names[i] = name; // 名字
                        addresses[i] = address; // 地址
                        states[i] = 0; // 订餐的状态
                        praiseNums[i] = number; // 份数
                        dishNames[i] = dishNames[num - 1]; // 定的菜品
                        distime[i] = time;
                        sumprice[i] = sumprices + deilcharge;
                        break;

                    }
                }
                break;

            case 2:
                System.out.println("2.查看餐袋");
                System.out.println("序号\t订餐人\t餐品信息\t送餐时间\t送餐地址\t总金额\t订单状态");
                for (int i = 0; i < names.length; i++) {
                    if (names[i] != null) {
                        String state = (states[i] == 0) ? "已预订" : "已完成";
                        String date = distime[i] + "点";
                        String Sumprice = sumprice[i] + "元";
                        System.out
                                .println((i + 1) + "\t" + names[i] + "\t"
                                        + dishNames[i] + "\t" + date + "\t"
                                        + addresses[i] + "\t" + Sumprice + "\t"
                                        + state);
                    }
                }

                break;
            case 3:
                System.out.println("3.签收订单");
                boolean isSignFind = false; // 找到要签收的订单序号
                System.out.println("请选择要签收的订单号:");
                int signOrderId = input.nextInt();
                for (int i = 0; i < names.length; i++) {
                    // 状态为已预订,序号为用户输入的订单书号减1:可签收
                    // 状态为完成,序号为用户输入的订单书号减1:不被签收
                    if (names[i] != null && states[i] == 0
                            && signOrderId == i + 1) {
                        System.out.println("订单已签收");
                        isSignFind = true;
                    } else if (names[i] != null && states[i] == 1
                            && signOrderId == i + 1) {
                        System.out.println("订单已签收,不能再次签收");
                        isSignFind = true;
                    }
                    if (!isSignFind) {
                        System.out.println("你的订单不存在");
                    }

                }
                break;
            case 4:
                System.out.println("4.删除订单");
                boolean isDelFind = false;
                int deId = input.nextInt();
                for (int i = 0; i < names.length; i++) {
                    if (names[i] != null && states[i] == 1 && deId == i + 1) {
                        isDelFind = true;
                        // 标记以找到此订单
                        for (int j = 0; j < names.length; j++) {
                            names[j] = names[j + 1];
                            dismegs[j] = dismegs[j + 1];
                            time[j] = time[j + 1];
                            addresses[j] = addresses[j + 1];
                            states[i] = states[i];
                            sumprice[i] = sumprice[j + 1];

                        }
                        int endindex = names.length - 1;
                        names[endindex] = null;
                        dismegs[endindex] = null;
                        time[endindex] = 0;
                        states[endindex] = 0;
                        sumprice[endindex] = 0.0;
                        System.out.println("删除订单成功");
                        break;

                    } else if (names[i] != null && states[i] == 0
                            && deId == i + 1) {
                        System.out.println("你的订单未能签收,不能删除");

                        isDelFind = false;
                        break;

                    }
                    if (!isDelFind) {
                        System.out.println("你要删除的订单不存在");
                    }
                }
                break;
            case 5:
                System.out.println("5.我要点赞");
                System.out.println("选择你要点赞的菜");
                int priaise = input.nextInt();
                praiseNum[priaise - 1]++;
                System.out.println("点赞成功");

                break;
            case 6:
                // 退出系统
                isExit = true;
                break;
            default:
                // 退出系统
                isExit = true;
                break;
            }
            if (!isExit) { // 默认这是不退出
                System.out.println("输入0返回主菜单!");
                num = input.nextInt();
            } else {
                break; // 退出系统
            }

        } while (num == 0);
        System.out.println("谢谢您的光临!!!!!");
    }
}

 

posted @ 2017-08-22 14:28  小白装大神  阅读(556)  评论(0编辑  收藏  举报