7.16 吃货联盟订餐系统的实现

吃货联盟订餐系统的实现

吃货联盟项目:

数据主体:
1、我要点餐:
姓名、菜名(提前预置)、份数、时间(10~20)、地点
2、查看餐袋(订单)
编号、订餐人、菜品名、份数、总价、时间、地址、状态
3、签收订单
4、删除订单
5、点赞
菜品信息:
编号、菜品名、单价、点赞数

代码实现:

public class ChiHuo {
    public static void main(String[] args) {
        final double NO_SEND_MONEY = 80;
        String[] dishes = {"东坡肉","地锅鸡","水煮鱼","佛跳墙"};
        double[] prices = {45,38,28,99};
        int[] like = {11,22,33,44};
        int chooseNum = 0;
        String[][] bills = new String[1024][];
        String name = null;
        int pcs = 0;
        int time = 0;
        String address = null;
        String status = null;
        Scanner sc = new Scanner(System.in);
        int choose = 0;
        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("*************************");
            System.out.print("请选择:");
            choose = sc.nextInt();
            switch(choose){
                case 1:
                    System.out.println("****我要订餐****");
                    System.out.print("请输入订餐人的姓名:");
                    name = sc.next();
                    System.out.println("序号\t菜品\t单价");
                    for (int i = 0; i < dishes.length; i++) {
                        System.out.println((i + 1) + "\t" + dishes[i] + "\t" + prices[i] + "元");
                    }
                    do {
                        System.out.print("请选择你要定的菜品编号:");
                        chooseNum = sc.nextInt();
                        if(chooseNum > 0 && chooseNum <= dishes.length)break;
                            System.out.println("您的输入有误,请重新输入:");
                    }while (true);
                    do {
                        System.out.print("请选择你需要的份数:");
                        pcs = sc.nextInt();
                        if(pcs >= 0) break;
                            System.out.println("份数不能小于0,重新输入!");
                    }while (true);
                    do {
                        System.out.print("请输入送餐时间(10点至20点整点送餐):");
                        time = sc.nextInt();
                        if(time >= 10 && time <= 20)break;
                        System.out.println("输入有误,重新输入!");
                    }while (true);
                    System.out.print("请输入送餐地址:");
                    address = sc.next();
                    System.out.println("订餐成功!");
                    System.out.println("您订的是:" + dishes[chooseNum - 1]);
                    System.out.println("送餐时间:" + time + "点");
                    double dishPrice = prices[chooseNum - 1] * pcs;
                    int sendMoney = 0;
                    if(dishPrice < NO_SEND_MONEY){
                        sendMoney = 6;
                    }
                    double totalPrice = dishPrice + sendMoney;
                    System.out.println("餐费:" + dishPrice + "元,送餐费" + sendMoney + "元,总计:" + totalPrice + "元");
                    //插入订单,遍历订单,如果为空则插入
                    for (int i = 0; i < bills.length; i++) {
                        if(bills[i] == null){
                            bills[i] = new String[6];
                            bills[i][0] = name;
                            bills[i][1] = dishes[chooseNum - 1] + " " + pcs + "份";
                            bills[i][2] = time + "点";
                            bills[i][3] = address;
                            bills[i][4] = totalPrice + "元" ;
                            bills[i][5] = "已预订" ;
                            break;
                        }
                    }
                    System.out.print("输入0返回:");
                    choose = sc.nextInt();
                    break;
                case 2:
                    System.out.println("****查看餐袋****");
                    System.out.println("序号\t点餐人\t餐品信息\t\t送餐日期\t送餐地址\t总金额\t订单状态");
                    for (int i = 0; i < bills.length; i++) {
                        if(bills[i] == null){
                            break;
                        }
                        System.out.println((i + 1) + "\t" + bills[i][0] + "\t\t" + bills[i][1] + "\t" + bills[i][2] + "\t\t" +
                                bills[i][3] + "\t\t" + bills[i][4] + "\t" + bills[i][5]);
                    }
                    System.out.print("输入0返回:");
                    choose = sc.nextInt();
                    break;
                case 3:
                    System.out.println("****签收订单****");
                    if(bills[0] == null){
                        System.out.println("订单为空,不可签收!");
                        System.out.println("输入0返回:");
                        choose = sc.nextInt();
                        break;
                    }
                    System.out.println("序号\t点餐人\t餐品信息\t\t总金额\t订单状态");
                    int i = 0;
                    for (; i < bills.length; i++) {
                        if(bills[i] == null){
                            break;
                        }
                        System.out.println((i + 1) + "\t" + bills[i][0] + "\t\t" + bills[i][1] + "\t" + bills[i][4] + "\t" + bills[i][5]);
                    }
                    int signNum;
                    do {
                        System.out.print("请选择要签收的订单编号:");
                        signNum = sc.nextInt();
                        if(signNum > 0 && signNum <= i)break;
                        System.out.println("订单不存在,请重新输入!");
                    }while (true);
                    if(bills[signNum - 1][5].equals("已完成")){
                        System.out.println("订单已完成签收,不需要重复签收!");
                    }
                    bills[signNum - 1][5] = "已完成";
                    System.out.print("输入0返回:");
                    choose = sc.nextInt();
                    break;
                case 4:
                    System.out.println("****删除订餐****");
                    if(bills[0] == null){
                        System.out.println("订单为空,不可删除!");
                        System.out.println("输入0返回:");
                        choose = sc.nextInt();
                        break;
                    }
                    //未完成的订单不能删除
                    //删除订单需要考虑选择的订单删除后,后面的订单需要前移
                    System.out.println("序号\t点餐人\t餐品信息\t\t总金额\t订单状态");
                    int k = 0;
                    for (; k < bills.length; k++) {
                        if(bills[k] == null){
                            break;
                        }
                        System.out.println((k + 1) + "\t" + bills[k][0] + "\t\t" + bills[k][1] + "\t" + bills[k][4] + "\t" + bills[k][5]);
                    }
                    int delNum;
                    do {
                        System.out.print("请选择要删除的订单编号:");
                        delNum = sc.nextInt();
                        if(delNum > 0 && delNum <= k)break;
                        System.out.println("订单不存在,请重新输入!");
                    }while (true);
                    if(!bills[delNum - 1][5].equals("已完成"))
                        System.out.println("未完成的订单不能删除!");
                    else {
                        for (int s = delNum - 1; bills[s] != null; s++) {
                            if(delNum == bills.length){
                                bills[delNum - 1] = null;
                            }else {
                                bills[s] = bills[s + 1];
                            }
                        }
                        System.out.println("删除完成!");
                    }
                    System.out.print("输入0返回:");
                    choose = sc.nextInt();
                    break;
                case 5:
                    System.out.println("****我要点赞****");
                    System.out.println("序号\t菜品\t\t单价\t\t点赞数");
                    for (int j = 0; j < dishes.length; j++) {
                        System.out.println((j + 1) + "\t" + dishes[j] + "\t" + prices[j] + "元" + "\t" + like[j]);
                    }
                    int likeNum ;
                    do {
                        System.out.print("选择需要点赞的菜品:");
                        likeNum = sc.nextInt();
                        if(likeNum > 0 && likeNum <= like.length)break;
                        System.out.print("没有这个菜品,请重新输入:");
                    }while (true);
                    like[likeNum - 1] ++;
                    System.out.println("谢谢点赞!");
                    System.out.print("输入0返回:");
                    choose = sc.nextInt();
                    break;
            }
        }while (choose == 0);
        System.out.println("谢谢使用,欢迎下次光临!");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值