吃货联盟
package com.chen; //菜单类 public class Menu { // 属性 序号 菜品名 单价 点赞数 private int num; private String name; private double price; private int zan; public int getNum() { return num; } public void setNum(int num) { this.num = num; } 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 int getZan() { return zan; } public void setZan(int zan) { this.zan = zan; } public static Menu[] getMenu() { return menu; } public static void setMenu(Menu[] menu) { Menu.menu = menu; } public Menu() { super(); } public Menu(int num, String name, double price, int zan) { super(); this.num = num; this.name = name; this.price = price; this.zan = zan; } // 数组 用来存菜品样式的 public static Menu[] menu = new Menu[10]; static { menu[0] = new Menu(1, "鱼香肉丝", 38.0, 555); menu[1] = new Menu(2, "爆炒牛肉", 20.0, 666); menu[2] = new Menu(3, "时令蔬菜", 10.0, 565); } //打印菜单 public static void toPrint() { System.out.println("序号"+"\t\t"+"菜品名"+"\t\t"+"单价"+"\t\t"+"点赞数"); for (Menu menu2 : menu) { if(menu2!=null) { System.out.println(menu2.num+"\t\t"+menu2.name+"\t\t"+menu2.price+"\t\t"+menu2.zan); } } } //查看菜单 public static void findInfo(int i) { System.out.println("序号"+"\t\t"+"菜品名"+"\t\t"+"单价"+"\t\t"+"点赞数"); System.out.println(menu[i-1].num+"\t\t"+menu[i-1].name+"\t\t"+menu[i-1].price+"\t\t"+menu[i-1].zan); } }
package com.chen; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class OrderInfo { // 初始化餐袋信息 // 序号 订单人 菜品名 份数 送餐时间 送餐地址 总金额 订单状态 public static List<UserMenu> list = new ArrayList<>(); static { list.add(new UserMenu(1, "李明", "鱼香肉丝", 1, 12, "厦门市思安", 38.0, "已完成")); list.add(new UserMenu(2, "张三", "爆炒牛肉", 2, 12, "厦门市思明", 40.0, "已预订")); } public static void toPrint() { System.out.println("序号" + "\t" + "订单人" + "\t\t" + "菜品信息" + "\t\t" + "份数" + "\t" + "送餐时间" + "\t\t" + "送餐地址" + "\t\t" + "总金额" + "\t\t" + "订单状态"); for (UserMenu userMenu : list) { System.out.println(userMenu.getXuHao() + "\t" + userMenu.getName() + "\t\t" + userMenu.getDishName() + "\t\t" + userMenu.getNum() + "\t" + userMenu.getTime() + "\t\t" + userMenu.getAddresses() + "\t" + userMenu.getMoneys() + "\t\t" + userMenu.getStates()); } } public static void toPrint(int i) { System.out.println("序号" + "\t" + "订单人" + "\t\t" + "菜品信息" + "\t\t" + "份数" + "\t" + "送餐时间" + "\t\t" + "送餐地址" + "\t\t" + "总金额" + "\t\t" + "订单状态"); System.out.println(list.get(i - 1).getXuHao() + "\t" + list.get(i - 1).getName() + "\t\t" + list.get(i - 1).getDishName() + "\t\t" + list.get(i - 1).getNum() + "\t" + list.get(i - 1).getTime() + "\t\t" + list.get(i - 1).getAddresses() + "\t" + list.get(i - 1).getMoneys() + "\t\t" + list.get(i - 1).getStates()); } public static void main(String[] args) { toPrint(1); } }
package com.chen; import java.util.Scanner; //测试类 public class TestDemo { static Scanner sc = new Scanner(System.in); static boolean flag = true; //判断是否退出系统 static int num01; public static void main(String[] args) { do { UserView.userView();; if(!flag==true) { break; }else { System.out.println("请输入0返回菜单"); num01 = sc.nextInt(); } }while(num01==0); System.out.println("谢谢你的使用"); } }
package com.chen; //餐袋 其实就是用户类自己的菜单 public class UserMenu { //序号 订单人 菜品名 份数 送餐时间 送餐地址 总金额 订单状态 private int xuHao; private String name; private String dishName; private int num; private int time; private String addresses; private double moneys; private String states; public UserMenu() { super(); } public UserMenu(int xuHao, String name, String dishName, int num, int time, String addresses, double moneys, String states) { super(); this.xuHao = xuHao; this.name = name; this.dishName = dishName; this.num = num; this.time = time; this.addresses = addresses; this.moneys = moneys; this.states = states; } public int getXuHao() { return xuHao; } public void setXuHao(int xuHao) { this.xuHao = xuHao; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDishName() { return dishName; } public void setDishName(String dishName) { this.dishName = dishName; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getTime() { return time; } public void setTime(int time) { this.time = time; } public String getAddresses() { return addresses; } public void setAddresses(String addresses) { this.addresses = addresses; } public double getMoneys() { return moneys; } public void setMoneys(double moneys) { this.moneys = moneys; } public String getStates() { return states; } public void setStates(String states) { this.states = states; } }
package com.chen; public class UserView { public static void userView() { View.view(); System.out.println("请选择:"); String choose = TestDemo.sc.next(); switch (choose) { case "1": userOrder(); // 调用我要订餐的方法(单独写一个 userOrder) break; case "2": lookOrder(); // 调用查看餐袋的方法(单独写一个 lookOrder) break; case "3": qianShouOrder(); // 调用签收订单的方法(单独写一个 qianShouOrder) break; case "4": shanChuOrder(); // 调用删除订单的方法(单独写一个 shanChuOrder) break; case "5": zan(); // 调用我要点赞的方法(单独写一个 zan) break; case "6": //// 调用退出系统的方法(单独写一个 exit()) exit(); break; default: // 输入的不是以上的,都默认为退出系统 TestDemo.flag = false; break; } } // 我要订餐的方法 public static void userOrder() { boolean boo = false; System.out.println("我要点餐"); // 实例化出来菜单类用来给用户看的 Menu.toPrint(); System.out.println("请输入订单人姓名:"); String name = TestDemo.sc.next(); System.out.println("请选择您要点的菜品编号"); int dex; do { dex = TestDemo.sc.nextInt(); if (dex >= 1 && dex <= 3) { break; } else { System.out.println("没有找到该菜品,请重新输入:"); boo = true; } } while (boo); String dishName = Menu.menu[dex - 1].getName(); System.out.println("您要几份"); int num = TestDemo.sc.nextInt(); double moneys = Menu.menu[dex - 1].getPrice() * num; // 送餐时间 System.out.println("请输入送餐时间(10至12整点送餐)"); int time; do { time = TestDemo.sc.nextInt(); if (time >= 10 && time <= 12) { break; } else { System.out.println("您输入的送餐时间错误,请重新输入(10点至12点整点送餐)"); boo = true; } } while (boo); // 送餐地址 System.out.println("请输入送餐地址:"); String addresses = TestDemo.sc.next(); // 订单状态 String states = "已预订"; // 序号 int xuHao = OrderInfo.list.size() + 1; // 用户餐袋 OrderInfo.list.add(new UserMenu(xuHao, name, dishName, num, time, addresses, moneys, states)); System.out.println("恭喜您订单成功,订单信息详细如下:"); OrderInfo.toPrint(); } // 查看餐袋的方法 public static void lookOrder() { System.out.println("****查看餐袋*****"); OrderInfo.toPrint(); } // 签收订单的方法 public static void qianShouOrder() { boolean flag1 = false; System.out.println("*****签收订单***"); OrderInfo.toPrint(); System.out.println("请选择要签收的订单(只能签收已预订的)"); int num; do { num = TestDemo.sc.nextInt(); if(num>OrderInfo.list.size()) { System.out.println("找不到你要签收的订单,请重新输入:"); flag1 = true; }else { if(OrderInfo.list.get(num-1).getStates().equals("已完成")) { System.out.println("已签收的不能再次签收"); }else if(OrderInfo.list.get(num-1).getStates().equals("已预订")) { OrderInfo.list.get(num-1).setStates("已完成"); System.out.println("签收成功!"); } } } while (flag1); } // 删除订单的方法 public static void shanChuOrder() { boolean flag2 = false; System.out.println("***删除订单*****"); OrderInfo.toPrint(); System.out.println("请输入要删除的订单编号:"); int num; do { num = TestDemo.sc.nextInt(); if (num > OrderInfo.list.size()) { System.out.println("找不到您要删除的订单,请重新输入:"); flag2 = true; } else { OrderInfo.list.remove(num - 1); System.out.println("删除订单成功!"); } } while (flag2); } // 实现我要点赞的方法 public static void zan() { boolean flag3 = false; System.out.println("我要点赞!"); Menu.toPrint(); System.out.println("请选择您要点赞的菜品序号"); int num; do { num = TestDemo.sc.nextInt(); if(num>Menu.getMenu().length) { System.out.println("找不到您要点赞的订单,请重新输入:"); flag3 = true; }else { Menu.menu[num-1].setZan(Menu.menu[num-1].getZan()+1); System.out.println("点赞成功"); Menu.toPrint(); } }while(flag3); } // 退出系统的方法 public static void exit() { System.out.println("退出系统,谢谢您的使用"); TestDemo.flag = false; } } //System.out.println("请选择您要点赞的菜品序号:"); //num = TestDemo.sc.nextInt(); //if(num<=Menu.menu.length) { // flag1 = false; // Menu.menu[num-1].setZan(Menu.menu[num-1].getZan()+1); // System.out.println("点赞成功!"); // Menu.findInfo(num); // break; //}else { // System.out.println("您选择的菜品序号不存在,请重新选择!:"); //}
package com.chen; public class View { public static void view() { System.out.println("**************************"); System.out.println("欢迎来到吃货联盟点餐系统"); System.out.println("1、我要订餐 2、查看餐袋 3、签收订单"); System.out.println("4、删除订单 5、我要点赞 6、退出系统"); System.out.println("*************************"); } }