package Order;
import javax.print.attribute.standard.OrientationRequested;
import java.awt.*;
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Map<Integer, Dish> dishMap = new HashMap<Integer, Dish>();
Map<Integer, Order> orderMap = new HashMap<Integer, Order>();
//初始化菜品并添加菜品集合
Dish dish1 = new Dish(1, "鱼香肉丝", 35, 1);
Dish dish2 = new Dish(2, "宫保鸡丁", 30, 0);
Dish dish3 = new Dish(3, "回锅肉", 42, 0);
Dish dish4 = new Dish(4, "地锅鸡", 35, 0);
Dish dish5 = new Dish(5, "麻婆豆腐", 12, 0);
Dish dish6 = new Dish(6, "黄焖鸡", 21, 0);
dishMap.put(dish1.getDishId(), dish1);
dishMap.put(dish2.getDishId(), dish2);
dishMap.put(dish3.getDishId(), dish3);
dishMap.put(dish4.getDishId(), dish4);
dishMap.put(dish5.getDishId(), dish5);
dishMap.put(dish6.getDishId(), dish6);
//初始化订单
Order order1 = new Order(1, "薛立阳", dish1.getDishName(), 1, 10, "北大青鸟", dish1.getPrice() * 1, 0);
Order order2 = new Order(2, "薛立阳", dish2.getDishName(), 1, 10, "北大青鸟", dish2.getPrice() * 1, 1);
orderMap.put(order1.getOrderId(), order1);
orderMap.put(order2.getOrderId(), order2);
int count=2;
//菜单
int choose = 1; //用户输入
boolean isExit = false; //是否退出,true为退出
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.print("请选择:");
choose = sc.nextInt();
//判断
switch (choose) {
case 1:
System.out.println("我要订餐---");
//新增订单
Order newOrder = new Order();
System.out.println("请输入订餐人姓名:");
newOrder.setName(sc.next());
//展示菜品信息
System.out.println("菜品编号" + "\t菜品名" + "\t\t价格" + "\t\t点赞数");
for (Dish dish : dishMap.values()) {
System.out.println(dish.getDishId() + "\t\t" + dish.getDishName() + "\t\t" + dish.getPrice() + "\t\t" + (dish.getPraise() == 0 ? "" : dish.getPraise() + "赞"));
}
System.out.print("请选择菜品编号:");
int chooseId=sc.nextInt();
if(chooseId>dishMap.size()){
System.out.println("不存在的菜品,请重新点单:");
chooseId=sc.nextInt();
}
newOrder.setOrderId(chooseId);
System.out.print("请选择需要份数:");
newOrder.setCount(sc.nextInt());
System.out.println("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
newOrder.setTime(sc.nextInt());
//判断是否在配送规定时间
while (newOrder.getTime() < 10 || newOrder.getTime() > 21) {
System.out.println("您的输入有误,请输入10-20间的整数");
newOrder.setTime(sc.nextInt());
}
System.out.println("请输入送餐地址:");
newOrder.setAddress(sc.next());
//结算金额
newOrder.setSumPrice(newOrder.getCount() * dishMap.get(chooseId).getPrice());
if (newOrder.getSumPrice() < 50) {
//如果金额小于50加五元配送费
System.out.println("总金额不足50,须加5元配送费");
newOrder.setSumPrice(newOrder.getSumPrice() + 5);
}
//打印信息
System.out.println("创建订单成功!");
System.out.println("您定的是:" + dishMap.get(newOrder.getOrderId()).getDishName() +"("+dishMap.get(newOrder.getOrderId()).getPrice()+"元)\t" + newOrder.getCount() + "份\n送餐时间是:" + newOrder.getTime() + "\n总计:" + newOrder.getSumPrice() + "元");
count++;
newOrder.setOrderId(count);
//存入数据
orderMap.put(newOrder.getOrderId(), newOrder);
break;
case 2:
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (Order order : orderMap.values()) {
System.out.println(order.getOrderId() + "\t" + order.getName() + "\t\t" +
order.getTime() + "\t\t\t" + order.getAddress() + "\t\t" + order.getSumPrice() +
"\t\t" + (order.getState() == 0 ? "已预订" : "已送达"));
}
break;
case 3:
System.out.println("****签收订单****");
System.out.print("请输入要签收的订单号:");
int id = sc.nextInt();
if(id>orderMap.size()){
System.out.println("该订单不存在");
}else if(orderMap.get(id).getState() == 0){
System.out.println("签收成功");
orderMap.get(id).setState(1);
}else if(orderMap.get(id).getState() == 1){
System.out.println("订单已签收,不能重复签收");
orderMap.get(id).setState(1);
}
break;
case 4:
System.out.println("***删除订单***");
System.out.print("请输入要删除的订单号:");
int delId = sc.nextInt();
boolean isDel=false;
//查询订单
for (int i = 1; i <= count; i++) {
//未签收
if(delId==i&&orderMap.get(i)!=null&&orderMap.get(i).getState()==0){
System.out.println("订单未签收,无法删除");
}else if(delId==i&&orderMap.get(i)!=null&&orderMap.get(i).getState()==1){
int j;
for ( j = i; j < count; j++) {
orderMap.put(j,orderMap.get(j+1)); //订单位置前移
}
orderMap.remove(j);
count--;
isDel=true;
System.out.println("删除成功");
break;
}
}
if(!isDel){
System.out.println("不存在的订单");
}
break;
case 5:
System.out.println("***我要点赞***");
//显示菜品信息
System.out.println("菜品编号" + "\t菜品名" + "\t\t价格" + "\t\t点赞数");
for (Dish dish : dishMap.values()) {
Sys
评论0