吃货联盟订餐系统

import java.util.Scanner;
public class Demo3 {
public static void main(String[] args) {
String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };//菜单
double[] prices = { 38.0, 20.0, 10.0 };//价格
int[] praiseNum = new int[3];//点赞数
String[] names = new String[4];//订餐人姓名
String[] dishMegs = new String[4];//订餐信息
int[] times = new int[4];//送餐时间
String[] addresses = new String[4];//送餐地址
int[] states = new int[4];//订单状态
double[] sumPrices = new double[4];//总价
int chooseNum = 0;
System.out.println("欢迎使用“吃货联盟订餐系统”");
do {
System.out.println("******************************\n");
System.out.println("1.我要订餐\n2.查看餐袋\n3.签收订单\n4.删除订单\n5.我要点赞\n6.退出系统");
System.out.println("******************************\n");
System.out.print("请选择:");
boolean exit = false;
boolean add = false;
Scanner input = new Scanner(System.in);
if (input.hasNextInt() != true) {
System.out.println("输入非法字符,请重新选择");
continue;
}
int choose = input.nextInt();// 菜单编号
if (choose > 6 || choose <= 0) {
System.out.println("输入数字有误,请重新选择");
continue;
}
switch (choose) {
case 1:
System.out.println("*******我要订餐*******");
System.out.print("请输入订餐人姓名:");
String name = input.next();// 订餐人名字
for (int i = 0; i < names.length; i++) {
if (names[i] == null) {
add = true;
System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
for (int j = 0; j < dishNames.length; j++) {
System.out.println((j + 1) + "\t" + dishNames[j] + "\t" + prices[j] + "\t" + praiseNum[j]);
}
System.out.print("请选择您要的菜品编号:");
Scanner input1 = new Scanner(System.in);
if (input1.hasNextInt() != true) {
System.out.println("输入非法字符,请重新选择");
continue;
}
int num = input1.nextInt();// 菜品编号
while (num < 1 || num > 3) {
System.out.print("输入错误,请重新输入:");
num = input1.nextInt();
}
System.out.print("请选择您需要的份数:");
int quantity = input.nextInt();// 数量
System.out.print("请输入送餐时间(送餐时间是10点到20点间整点送餐):");
int time = input.nextInt();
while (time < 10 || time > 20) {
System.out.print("输入错误,请重新输入:");
time = input.nextInt();
}
System.out.print("请输入送餐地址:");
String address = input.next();
System.out.println("订餐成功!");
System.out.println("您订的是:" + dishNames[num - 1] + " " + quantity + "份");
System.out.println("送餐时间:" + time + "点");
double totalMoney = prices[num - 1] * quantity;
int cost = 5;
if (totalMoney >= 50) {
cost = 0;
}
double sumMoney = totalMoney + cost;
names[i] = name;
dishMegs[i] = dishNames[num - 1];
times[i] = time;
addresses[i] = address;
sumPrices[i] = sumMoney;
states[i] = 0;
System.out.println("餐费:" + totalMoney + "元, 送餐费:" + cost + "元, 总计:" + (totalMoney + cost) + "元.");
System.out.print("是否返回主菜单(输入0返回,否则退出系统):");
chooseNum = input.nextInt();
if (chooseNum == 0) {
break;
} else {
exit = true;
break;
}
}
}
if (add == false) {
System.out.println("餐袋已满,无法订餐");
break;
}
break;
case 2:
System.out.println("*******查看餐袋*******");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t总金额\t订单状态");


for (int j = 0; j < names.length; j++) {
String state = states[j] == 0 ? "已预订" : "已完成";
if (names[j] != null) {
System.out.println((j + 1) + "\t" + names[j] + "\t" + dishMegs[j] + "\t\t" + times[j] + "\t"
+ addresses[j] + "\t\t" + sumPrices[j] + "\t" + state);
}
}
System.out.print("是否返回主菜单(输入0返回,否则退出系统):");
chooseNum = input.nextInt();
if (chooseNum == 0) {
break;
} else {
exit = true;
break;
}
case 3:
System.out.println("*******签收订单*******");
System.out.print("请选择要签收的订单序号:");
int num = input.nextInt();
if (names[num - 1] != null && states[num - 1] == 0) {
states[num - 1] = 1;
System.out.println("订单签收成功!");
} else if (states[num - 1] == 1) {
System.out.println("此订单已签收,不能重复签收!");
} else {
System.out.println("您选择的订单不存在!");
}
System.out.print("是否返回主菜单(输入0返回,否则退出系统):");
chooseNum = input.nextInt();
if (chooseNum == 0) {
break;
} else {
exit = true;
break;
}
case 4:
System.out.println("*******删除签收*******");
System.out.print("请选择要删除的订单序号:");
int num1 = input.nextInt();
if (names[num1 - 1] != null && states[num1 - 1] == 1) {
for (int i = num1; i < sumPrices.length; i++) {
names[i - 1] = names[i];
dishMegs[i - 1] = dishMegs[i];
times[i - 1] = times[i];
addresses[i - 1] = addresses[i];
sumPrices[i - 1] = sumPrices[i];
states[i - 1] = states[i];
int index = names.length - 1;
names[index] = null;
dishMegs[index] = null;
times[index] = 0;
addresses[index] = null;
sumPrices[index] = 0.0;
states[index] = 0;
System.out.println("订单删除成功!");
break;
}
} else if (names[num1 - 1] != null && states[num1 - 1] == 0) {
System.out.println("此订单未签收,不能删除签收!");
break;
} else {
System.out.println("您选择的订单不存在!");
}
System.out.print("是否返回主菜单(输入0返回,否则退出系统):");
chooseNum = input.nextInt();
if (chooseNum == 0) {
break;
} else {
exit = true;
break;
}
case 5:
System.out.println("*******我要点赞*******");
System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
for (int j = 0; j < dishNames.length; j++) {
System.out.println((j + 1) + "\t" + dishNames[j] + "\t" + prices[j] + "\t" + praiseNum[j]);
}
System.out.print("请输入要点赞的菜品:");
int num2 = input.nextInt();
if (num2 <= 3 && num2 >= 1) {
praiseNum[num2 - 1]++;
System.out.println("点赞成功!");
} else {
System.out.println("不存在的菜品,不能点赞");
}
System.out.print("是否返回主菜单(输入0返回,否则退出系统):");
chooseNum = input.nextInt();
if (chooseNum == 0) {
break;
} else {
exit = true;
break;
}
case 6:
exit = true;
break;
}
if (exit != true) {
continue;
} else {
break;
}
} while (chooseNum == 0);
System.out.println("谢谢使用吃货联盟点餐系统,欢迎下次光临!");
}
}
阅读更多

没有更多推荐了,返回首页