• 使用吃货联盟订餐系统超级详解两种方式======来自欣欣


    深夜的清秋我在写吃货

    吃货订餐系统的结果图:

    我的吃货需求:

    方案一:用我的对象数组来实现

    写我的类:

    菜单类 订单类 枚举类

    我的菜单类和订单类一样:

    Menu和Order:

    package entity;
    
    public class Menu {
    
            private Integer id;
            private String name;
            private double price;
            private Integer evaluate;
    
            public Integer getId() {
                return id;
            }
    
            public void setId(Integer id) {
                this.id = id;
            }
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
    
            public double getPrice() {
                return price;
            }
    
            public void setPrice(double price) {
                this.price = price;
            }
    
            public Integer getEvaluate() {
                return evaluate;
            }
    
            public void setEvaluate(Integer evaluate) {
                this.evaluate = evaluate;
            }
    }
    package entity;
    
    public class Order {
    
        private Integer id;
        private String name;
        private String info;
        private Integer date;
        private String adress;
        private double price;
        private OrderState orderState;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getInfo() {
            return info;
        }
    
        public void setInfo(String info) {
            this.info = info;
        }
    
        public Integer getDate() {
            return date;
        }
    
        public void setDate(Integer date) {
            this.date = date;
        }
    
        public String getAdress() {
            return adress;
        }
    
        public void setAdress(String adress) {
            this.adress = adress;
        }
    
        public double getPrice() {
            return price;
        }
    
        public void setPrice(double price) {
            this.price = price;
        }
    
        public OrderState getOrderState() {
            return orderState;
        }
    
        public void setOrderState(OrderState orderState) {
            this.orderState = orderState;
        }
    }
    package entity;
    
    public enum OrderState {
    
        已预订,已完成
    }

    呈现给顾客的页面:

    package mainl;
    
    import java.util.Scanner;
    
    public class MyTest {
    
        public static void main(String[] args) {
              show();
        }
    
        public static void show() {
            InitArray initArray = new InitArray();
            Scanner scanner = new Scanner(System.in);
            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.println("请选择");
    
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    initArray.showMenu();
                    returnMenu();
                    break;
                case 2:
                    initArray.showOrder();
                    returnMenu();
                    break;
                case 3:
                    initArray.writeOrder();
                    returnMenu();
                    break;
                case 4:
                    initArray.deleteOrder();
                    returnMenu();
                    break;
                case 5:
                    initArray.evaluate();
                    returnMenu();
                    break;
                case 6:
                    System.out.println("退出程序");
                    System.exit(1);
                    break;
    
                default:
                    break;
            }
    
        }
    
        public static void returnMenu() {
            Scanner scanner = new Scanner(System.in);
            System.out.println("返回主菜单(0)");
            int fanhui = scanner.nextInt();
            if (fanhui == 0) {
                show();
            } else {
                System.out.println("程序结束!");
            }
    
        }
    }

    主页面switch里

    package mainl;
    
    import java.util.Scanner;
    
    import entity.Menu;
    import entity.Order;
    import entity.OrderState;
    
    public class InitArray {
          static Menu[] menu=new Menu[100];
          static Order[] order=new Order[100];
          Scanner scanner=new Scanner(System.in);
          static{
             
                menu[0]=new Menu();  
                menu[0].setId(1);
                menu[0].setName("红烧鱼1");
                menu[0].setPrice(32);
                menu[0].setEvaluate(0);
              
                menu[1] = new Menu();
            menu[1].setId(2);
            menu[1].setName("红烧鱼2");
            menu[1].setPrice(32);
            menu[1].setEvaluate(0);
    
            menu[2] = new Menu();
            menu[2].setId(3);
            menu[2].setName("红烧鱼3");
            menu[2].setPrice(32);
            menu[2].setEvaluate(0);
    
         }
    
    public viod showMenu(){
               int num=0;  
               System.out.println("***我要订餐***");
           System.out.println("请输入订餐人姓名:");
           for(int i=0;i<InitArray.order.length;i++){
                     if(InitArray.order[i]==null){
                          InitArray.order[i]=new Order();
                          InitArray.order[i].setId(i+1);
                          InitArray.order[i].setName(Scanner.next());
                          num=i;
                          break;
            }
    
         }    
              System.out.println("序号" + "	" + "菜名" + "	" + "单价");
              for(Menu item:InitArray.menu){
                     if(item!=null){
                           system.out.println(item.getId()+"	"+item.getName()            +"	"+item.getPrice()):
                }
             }
              System.out.println("请输入你要点的菜品编号");
          int id = scanner.nextInt();
          String foodName = "";
          double price = 0;
              for(Menu item:menu){
                   if(item.getId()==id){
                         foodname=item.getName();
                         price=item.getPrice();
                         break;
             }
         }
                    System.out.println("请输入选择份数:");
            Integer sum = scanner.nextInt();
            InitArray.order[num].setInfo(foodName + " " + sum + "份");
    
            System.out.println("请输入送餐时间(送餐时间是从10点到20点整点):");
            InitArray.order[num].setDate(scanner.nextInt());
    
            System.out.println("请输入送餐地址:");
            InitArray.order[num].setAdress(scanner.nextLine());
    
            InitArray.order[num].setPrice(sum * price);
            InitArray.order[num].setOrderState(OrderState.已预订);
            System.out.println("订餐成功");
    
            System.out.println("您订的是" + InitArray.order[num].getInfo());
            System.out.println("送餐时间" + InitArray.order[num].getDate() + "点");
            System.out.println("餐费" + InitArray.order[num].getPrice() + ",送餐费0元,总计"
                    + InitArray.order[num].getPrice());
    }
    
    public void showOrder() {
            System.out.println("***查看餐袋***");
            System.out.println("序号" + "	" + "订餐人" + "	" + "餐品信息" + "	" + "送餐日期"
                    + "	" + "送餐地址" + "	" + "总金额" + "	" + "完成状态");
            for (Order item : InitArray.order) {
                if (item != null) {
                    System.out.println(item.getId() + "	" + item.getName() + "	"
                            + item.getInfo() + "	" + item.getDate() + "	"
                            + item.getAdress() + "	" + item.getPrice() + "	"
                            + item.getOrderState());
                }
            }
        }
    
        public void writeOrder() {
            System.out.println("***签收订单***");
            System.out.println("请选择要签收的订单号");
            Integer id = scanner.nextInt();
            for (Order item : InitArray.order) {
                if (item.getId() == id) {
                    if (item.getOrderState() == OrderState.已完成) {
                        System.out.println("已经签收不能重复签收");
                    } else {
                        item.setOrderState(OrderState.已完成);
                        System.out.println("订单签收成功");
                        break;
                    }
                }
            }
        }
    
        public void deleteOrder() {
            System.out.println("***删除订单***");
            System.out.println("请选择要删除的订单号");
            Integer id = scanner.nextInt();
            for (int i = 0; i < InitArray.order.length; i++) {
                if (InitArray.order[i] != null) {
                    if (InitArray.order[i].getOrderState() == OrderState.已完成) {
                        if (InitArray.order[i] == InitArray.order[id - 1]) {
                            InitArray.order[i] = null;
                            for (int j = i; j < InitArray.order.length; j++) {
                                if (InitArray.order[j] != null) {
                                    if (InitArray.order[j + 1] != null) {
                                        InitArray.order[j] = InitArray.order[j + 1];
                                    }
                                }
                            }
                            System.out.println("删除成功!");
    
                        }
                    } else {
                        System.out.println("订单未签收,不能删除订单");
                        break;
                    }
                }
            }
    
        }
    
        public void evaluate() {
            System.out.println("***我要点赞***");
            System.out.println("序号" + "	" + "菜名" + "	" + "单价" + "	" + "点赞");
            for (Menu item : InitArray.menu) {
                if (item != null) {
                    System.out.println(item.getId() + "	" + item.getName() + "	"
                            + item.getPrice() + "	" + item.getEvaluate());
                }
            }
            System.out.println("请输入您要点赞的序号");
            Integer id = scanner.nextI
    
    
    
    
    
    }
    
    }

    方案二:List集合:

    在我的entity类:

    package cn.canting;
    
    public class entil {
    
        public String name;
        public double money;
        public int id;
        public int add;
        public int num;
        public double sumMoney;
        public String address;
        public int time;
        public int dian=0;
        public int dingdan;
    }

    显示给我用户的页面:

    package cn.canting;
    
    import java.io.InputStream;
    import java.nio.channels.SelectableChannel;
    import java.util.ArrayList;
    import java.util.InputMismatchException;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Scanner;
    
    import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;
    
    public class can {
        static Scanner input = new Scanner(System.in);
        static Scanner input1 = new Scanner(System.in);
        public static List<entil> list = new ArrayList<entil>();
        public static List<entil> listNew = new ArrayList<entil>();
    
        public static void main(String[] args) {
            boolean flag = true;
    
            wwd();
    
        }
    
        public static void wwd() {
    
            add();
    
            Show();
            System.out.println("请输入要使用的功能");
    
            boolean flag = input.hasNextInt();
    
            while (!flag) {
                input = new Scanner(System.in);
                System.out.println("请输入数字");
    
                flag = input.hasNextInt();
            }
            int num = input.nextInt();
            num(num);
    
        }
    
        public static void Show() {
    
            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.退出");
        }
    
        public static void num(int num) {
    
            switch (num) {
            case 1:
                boolean flags = true;
                select();
    
                int num2 = 0;
                do {
                    System.out.println("请输入要点的餐");
                    if (!input.hasNextInt()) {
                        input = new Scanner(System.in);
    
                        flags = false;
                    } else {
                        num2 = input.nextInt();
                        flags = true;
                        if (num2 > 3) {
                            boolean f = true;
                            do {
                                System.out.println("请输入正确的点餐编号");
    
                                num2 = input.nextInt();
                                if (num2 <= 3 && num2 > 0) {
                                    f = false;
                                }
                            } while (f == true);
                            System.out.println("请输入要点餐的数量");
                            int num3 = input1.nextInt();
    
                            System.out.println("请输入要送餐的地址");
                            String address = input1.next();
                            boolean flag = false;
                            int time = 0;
                            do {
                                System.out.println("请输入要送餐的时间(10点到22点之间)");
    
                                time = input1.nextInt();
                                if (time >= 10 && time <= 22) {
                                    flag = false;
                                } else {
                                    System.out.println("请重新输入");
                                    flag = true;
                                }
                            } while (flag == true);
                            for (entil item : list) {
                                if (item.id == num2) {
                                    item.dingdan = listNew.size() + 1;
                                    item.address = address;
                                    item.time = time;
                                    item.num = num3;
                                    listNew.add(item);
                                    item.sumMoney = item.money * num3;
                                }
    
                            }
                            System.out.println("订餐成功");
                        } else {
    
                            System.out.println("请输入要点餐的数量");
                            int num3 = input1.nextInt();
    
                            System.out.println("请输入要送餐的地址");
                            String address = input1.next();
                            boolean flag = false;
                            int time = 0;
                            do {
                                System.out.println("请输入要送餐的时间(10点到22点之间)");
    
                                time = input1.nextInt();
                                if (time >= 10 && time <= 22) {
                                    flag = false;
                                } else {
                                    System.out.println("请重新输入");
                                    flag = true;
                                }
                            } while (flag == true);
                            for (entil item : list) {
                                if (item.id == num2) {
                                    item.dingdan = listNew.size() + 1;
                                    item.address = address;
                                    item.time = time;
                                    item.num = num3;
                                    listNew.add(item);
                                    item.sumMoney = item.money * num3;
                                }
    
                            }
                            System.out.println("订餐成功");
                        }
                    }
                } while (flags == false);
    
                System.out.println("按0返回");
                int zero = input.nextInt();
                if (zero == 0) {
                    Show();
                    System.out.println("请输入要使用的功能");
                    int num5 = input.nextInt();
                    num(num5);
                }
                break;
            case 2:
                Showt();
                input = new Scanner(System.in);
                System.out.println("按0返回");
                zero = input.nextInt();
                if (zero == 0) {
                    Show();
                    System.out.println("请输入要使用的功能");
                    int num5 = input.nextInt();
                    num(num5);
                }
                break;
            case 3:
                caozuo();
                input = new Scanner(System.in);
                System.out.println("按0返回");
                zero = input.nextInt();
                if (zero == 0) {
                    Show();
                    System.out.println("请输入要使用的功能");
                    int num5 = input.nextInt();
                    num(num5);
                }
                break;
            case 4:
                input = new Scanner(System.in);
                delect();
                System.out.println("按0返回");
                zero = input.nextInt();
                if (zero == 0) {
                    Show();
                    System.out.println("请输入要使用的功能");
                    int num5 = input.nextInt();
                    num(num5);
                }
                break;
            case 5:
                zan();
                input = new Scanner(System.in);
                System.out.println("按0返回");
                zero = input.nextInt();
                if (zero == 0) {
                    Show();
                    System.out.println("请输入要使用的功能");
                    int num5 = input.nextInt();
                    num(num5);
                }
                break;
            case 6:
                System.out.println("退出成功");
                break;
            default:
                break;
            }
    
        }
    
        public static void add() {
    
            entil en = new entil();
    
            en.id = 1;
            en.name = "红烧牛肉";
            en.money = 25;
            en.sumMoney = 0;
            en.add = 0;
    
            entil en1 = new entil();
    
            en1.id = 2;
            en1.name = "红烧猪蹄";
            en1.money = 20;
            en1.sumMoney = 0;
            en1.add = 0;
    
            entil en2 = new entil();
    
            en2.id = 3;
            en2.name = "红烧猪肉";
            en2.money = 30;
            en2.sumMoney = 0;
            en2.add = 0;
            list.add(en);
            list.add(en1);
            list.add(en2);
        }
    
        public static void select() {
    
            System.out.println("本餐厅菜单****************************");
            System.out.println("菜品编号		菜品名称		菜品价格		菜品点赞次数");
            for (entil item : list) {
                System.out.println(item.id + "		" + item.name + "		"
                        + item.money + "		" + item.add);
            }
    
        }
    
        public static void Showt() {
            System.out
                    .println("订单编号		菜品编号		菜品名称		菜品价格		送餐地址		点餐数量		总价");
            for (entil item : listNew) {
                if (item.dian == 1) {
                    System.out.println(item.dingdan + "		" + item.id + "		"
                            + item.name + "		" + item.money + "		"
                            + item.address + "		" + item.num + "		"
                            + item.sumMoney);
                }
            }
        }
    
        public static void caozuo() {
            System.out.println("未提交菜单");
            System.out
                    .println("订单编号		菜品编号		菜品名称		菜品价格		送餐地址		点餐数量		总价");
            for (entil item : listNew) {
                if (item.dian == 0) {
    
                    System.out.println(item.dingdan + "		" + item.id + "		"
                            + item.name + "		" + item.money + "		"
                            + item.address + "		" + item.num + "		"
                            + item.sumMoney);
                }
            }
            System.out.println("请选择提交的订单编号");
    
            int num = input.nextInt();
            int num2 = 0;
            for (entil item : listNew) {
                if (item.dian == 0) {
                    if (num == item.dingdan) {
                        item.dian = 1;
                        num2 = 1;
                    }
                }
            }
            if (num2 == 0) {
                System.out.println("无此编号");
            } else {
                System.out.println("提交成功");
            }
        }
    
        public static void delect() {
    
            for (entil item : listNew) {
                if (item.dian == 1) {
    
                    System.out.println(item.dingdan + "		" + item.id + "		"
                            + item.name + "		" + item.money + "		"
                            + item.address + "		" + item.num + "		"
                            + item.sumMoney);
                }
            }
            System.out.println("请选择删除的订单号码");
            int num = input.nextInt();
            int num2 = 0;
            for (entil item : listNew) {
                if (item.dian == 0) {
                    if (num == item.dingdan) {
                        listNew.remove(item);
                        num2 = 1;
                    }
                }
    
            }
            if (num2 == 0) {
                System.out.println("无此编号");
            } else {
                System.out.println("删除成功");
            }
    
        }
    
        public static void zan() {
    
            System.out.println("本餐厅菜单****************************");
            System.out.println("菜品编号		菜品名称		菜品价格		菜品点赞次数");
            for (entil item : list) {
                System.out.println(item.id + "		" + item.name + "		"
                        + item.money + "		" + item.add);
            }
            System.out.println("请选择点赞的商品编号");
            int num = input.nextInt();
            for (entil item : list) {
                if (item.id == num) {
                    item.add = item.add + 1;
                }
    
            }
            System.out.println("点赞成功,是否继续(0退出,其他任意数字键继续)");
            int num2 = input.nextInt();
            if (num2 != 0) {
    
                zan();
            }
    
        }
    }

                                                                                             孩子们不切实际的

                                                                                             燃烧着纯粹的心灵

  • 相关阅读:
    ES6---async, await, promise 综合例子
    ES6---Promise应用: async, await
    ES6---Promise 4: 更多案例
    掌握这两个技术点,你可以玩转AppCan前端开发
    AppCan4.0:开发者要做有价值的APP
    以“掌上东航”为例,论混合开发在企业级项目中的实践
    基于AppCan MAS系统,如何轻松实现移动应用数据服务?
    正益移动王国春:布局在是与不是之间
    【TOP10 APP】这些应用成了AppCan千人大会的焦点
    我爱我家:我为什么选择AppCan?
  • 原文地址:https://www.cnblogs.com/chengzixin/p/6831099.html
Copyright © 2020-2023  润新知