public class 订餐系统 {
public static void main(String[] args) {
System.out.println("*********欢迎来到吃货联盟***********");
String[] dishes = {"宫保鸡丁", "蒸熊掌", "红烧鲫鱼", "佛跳墙", "麻婆豆腐" };
int[] prices = {36, 45, 54, 78, 21};
int[] honors = new int[5];
final double SEND_PRICE = 6;
String[][] bills = new String[100][];
Scanner s = new Scanner(System.in);
int choice ;
do {
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("请进行您的选择:");
choice=s.nextInt();
switch (choice) {
case 1://我要订餐
System.out.println("*****请开始点餐*****");
System.out.print("请输入您的姓名");
String name = s.next();
//展示菜单
System.out.println("序号t菜名tt价格t点赞数");
for (int i = 0; i < dishes.length; i++) {
System.out.println(i + 1 + "t" + dishes[i] + "t" + prices[i] + "tt" + honors[i]);
}
System.out.println("请输入您要点的菜品编号:");
int num = s.nextInt();
System.out.println("请输入份数:");
int fen = s.nextInt();
System.out.println("请输入要送餐的时间(10-20)点:");
int time = s.nextInt();
System.out.println("请输入要送餐的地址:");
String add = s.next();
double total = prices[num - 1] * fen;
total = total > 100 ? total : total + SEND_PRICE;//三元表达式判断配送费
System.out.println("------------------------------");
System.out.println("恭喜点餐成功,您点的餐为:" + dishes[num - 1] + "n份数为:" + fen + "n送餐时间为:" + time + "n送餐地址为:" + add + "n总金额为:" + total);
//插入订单
for (int i = 0; i < bills.length; i++) {
if (bills[i] == null) {
bills[i] = new String[]{dishes[num - 1] + "t" + fen + "t" + total + "t" + name + "t" + time + "t" + add, "已预订" };
break;
}
}
break;
case 2://查看订单
System.out.println("*****查看您的订单*****");
System.out.println("序号t菜名tt份数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" + bills[i][1]);
}
break;
case 3://确认订单
System.out.println("*****请选择要确认的订单编号*****");
int billNum = s.nextInt();
if (bills[billNum - 1] == null) {
System.out.println("订单不存在");
} else if (bills[billNum - 1][1].equals("已完成")) {
System.out.println("订单已完成,不能重复确认!");
} else {
bills[billNum - 1][1] = "已完成";
System.out.println("订单确认成功!");
}
break;
case 4://删除订单
System.out.println("查看订单");
System.out.println("序号t菜名tt份数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" + bills[i][1]);
}
System.out.println("请选择要删除的订单编号");
int delNum = s.nextInt();
if (bills[delNum - 1] == null) {
System.out.println("订单不存在,删除失败");
} else if (bills[delNum - 1][1].equals("已预订")) {
System.out.println("订单未完成,不能删除!");
} else {
for (int i = delNum - 1; i < bills.length; i++) {
bills[i] = bills[i + 1];
if (bills[i + 1] == null) {
break;
}
bills[delNum - 1][1] = "已完成";
System.out.println("订单删除成功!");
}
}
break;
case 5://进行点赞
System.out.println("序号t菜名tt价格t点赞数");
for (int i = 0; i < dishes.length; i++) {
System.out.println(i + 1 + "t" + dishes[i] + "t" + prices[i] + "tt" + honors[i]);
}
System.out.println("请输入您要点赞的菜品");
int honorNum=s.nextInt();
honors[honorNum-1]++;
break;
case 6:
break;
default:
}
} while (choice > 0 && choice < 60);
System.out.println("谢谢惠顾,欢迎下次光临");
}
}