吃货大联盟的项目

package bdqn;


import java.util.Scanner;


public class chihuo {
public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
// 初始化订餐人姓名数组
String name[] = new String[4];
// 初始化菜品信息数组
String disMegs[] = new String[4];
// 初始化送餐时间数组
int times[] = new int[4];
// 初始化送餐地址数组
String address[] = new String[4];
// 初始化订单状态数组,0表示已预订,1表示已完成
int state[] = new int[4];
// 初始化订单的总金额数组
double sumPrice[] = new double[4];


// 初始化2个订单信息
name[0] = "张飞";
disMegs[0] = "东坡肘子 2份";
times[0] = 11;
address[0] = "屯溪路193号";
sumPrice[0] = 98.0;
state[0] = 1;


name[1] = "张龙";
disMegs[1] = "扣三丝 2份";
times[1] = 18;
address[1] = "天成路207号";
sumPrice[1] = 178.0;
state[0] = 0;


// 初始化供选择的菜品信息
String disNames[] = { "东坡肘子", "佛跳墙", "扣三丝" };
double price[] = { 49, 129, 89 };// 菜品价格
int dianZan[] = new int[3];// 点赞


System.out.println("欢迎使用\"吃货联盟订餐系统\"");
String n = "0";
go: 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("请选择:");
int num = input.nextInt();
switch (num) {
case 1: {
String answer = "y";
ok: do {
for (int j = 0; j < name.length; j++) {
if (name[j] == null) {
System.out.println("***我要订餐***");
System.out.println("**************菜品信息**************");
System.out.println("序号\t名称\t价格\t点赞");
for (int i = 0; i < disNames.length; i++) {
System.out.println((i + 1) + "\t" + disNames[i] + "\t" + price[i] + "\t" + dianZan[i]);
}
System.out.println("**********************************");
System.out.print("请选择菜单序号:");
int index = input.nextInt();// 菜单序号
// 如果菜单号选择不对,让他输入到手软,直到正确为止
while (index > 3 || index < 1) {
System.out.print("请选择1-3号菜品序号");
index = input.nextInt();
if (index > 0 && index <= 3) {
break;
}
}
System.out.print("请输入订餐人姓名:");
String nameOrder = input.next();// 订餐人姓名
System.out.print("请输入订餐数量:");
int numOrder = input.nextInt();// 订餐数量
double priceOrder = price[index - 1] * numOrder;// 单价*订餐数量
// 如果订餐总额达50元,免费送餐,否则要付5元送餐费
double rate = (priceOrder >= 50) ? 0 : 5;
// 总餐费是餐费+运送费
double sumPriceOrder = priceOrder + rate;
// 订餐信息描述
String disMeg = disNames[index - 1] + numOrder + "份";
System.out.print("请输入订餐时间:");
int timeOrder = input.nextInt();// 订餐时间
while (timeOrder < 8 || timeOrder > 20) {
System.out.print("订餐时间为早8点-晚20点,请重新输入:");
timeOrder = input.nextInt();
}
System.out.print("请输入送餐地址:");
String addOrder = input.next();
System.out.println("订餐成功!");
// 显示订餐信息
System.out.println("您定的是:" + disMeg);
System.out.println("送餐时间:" + timeOrder + "点");
System.out.println("餐费是:" + priceOrder + ",运费是:" + rate + ",总计:" + sumPriceOrder + "元");
// 把订餐信息保存得到数组中去
name[j] = nameOrder;
disMegs[j] = disMeg;
times[j] = timeOrder;
address[j] = addOrder;
sumPrice[j] = sumPriceOrder;
break;
} else if (j == name.length - 1) {// 找到最后一个,还没有空位说明已经元素已经满了
System.out.println("您的餐袋已满!");
break ok;// 直接跳出do-while循环
}
}
System.out.print("是否继续点餐(y/n):");
answer = input.next();
} while (answer.equals("y"));
break;
}
case 2: {
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t订单状态\t总金额");
for (int i = 0; i < name.length; i++) {
if (name[i] != null) {
System.out.println((i + 1) + "\t" + name[i] + "\t" + disMegs[i] + "\t " + times[i] + "\t"
+ address[i] + "\t" + state[i] + "\t" + sumPrice[i]);
}
}
break;
}
case 3: {
System.out.println("***签收订单***");
System.out.print("请选择要签收的订单序号:");
int orderId = input.nextInt();
while (true) {// 如果输入的单号超出范围,则提示重新输入
if (orderId < 1 || orderId > name.length) {
System.out.print("请输入1-4的数字:");
orderId = input.nextInt();
} else {
break;
}
}
boolean flag = false;// 默认条件是假,设立是否找到的标记,false没找到,true找到了
for (int i = 0; i < name.length; i++) {
if (name[i] != null && state[i] == 0 && orderId == i + 1) {
state[i] = 1;// 找到目标元素,把值修改成1
System.out.println("编号" + (i + 1) + "的定单已签收成功!");
flag = true;// 表示找到了
} else if (name[i] != null && state[i] == 1 && orderId == i + 1) {
System.out.println("此订单已签收,不能重复签收!");
flag = true;// 表示找到了
}
}
if (!flag) {// 当flag=false时,!flag=ture,if语句执行
System.out.println("没有此编号订单!");
}
break;
}
case 4: {
String answer = "y";
do {
System.out.println("***删除订单***");
System.out.print("请输入要删除的订单号:");
int deleteId =input.nextInt();
while (true) {// 如果输入的单号超出范围,则提示重新输入
if (deleteId < 1 || deleteId > name.length) {
System.out.print("请输入1-4的数字:");
deleteId =input.nextInt();
} else {
break;
}
}
boolean flag = false;// 默认条件是假,设立是否找到的标记,false没找到,true找到了
for (int i = 0; i < name.length; i++) {
if (name[i] != null && state[i] == 1 && deleteId == i + 1) {
flag = true;// 表示找到了,已经签收,可以删除
// 把要删除元素后面的元素向前移一位把要删除元素覆盖,然后把最后一位元素设置为null或0
for (int j = deleteId - 1; j < name.length - 1; j++) {
name[j] = name[j + 1];
disMegs[j] = disMegs[j + 1];
times[j] = times[j + 1];
address[j] = address[j + 1];
sumPrice[j] = sumPrice[j + 1];
state[j] = state[j + 1];
}
name[name.length - 1] = null;
disMegs[name.length - 1] = null;
times[name.length - 1] = 0;
address[name.length - 1] = null;
state[name.length - 1] = 0;
sumPrice[name.length - 1] = 0;
System.out.println("删除订单成功!");
break;
} else if (name[i] != null && state[i] == 0 && deleteId == i + 1) {
flag = true;// 表示找到了,没有签收,不能删除
System.out.println("订单没有签收,不能删除!");
break;
}
}
if (!flag) {// 当flag=false时,!flag=ture,if语句执行
System.out.println("您要删除的订单不存在!");
}
System.out.print("是否继续删除(y/n):");
answer = input.next();
} while (answer.equals("y"));
break;
}
case 5: {
String answer = "y";
do {
System.out.println("***我要点赞***");
System.out.println("**************菜品信息**************");
System.out.println("序号\t名称\t价格\t点赞");
for (int i = 0; i < disNames.length; i++) {
System.out.println((i + 1) + "\t" + disNames[i] + "\t" + price[i] + "\t" + dianZan[i]);
}
System.out.println("**********************************");
System.out.print("请选择要点赞的菜单序号:");
int index = input.nextInt();// 菜单序号
// 如果菜单号选择不对,让他输入到手软,直到正确为止
while (index > 3 || index < 1) {
System.out.print("请选择1-3号菜品序号");
index =input.nextInt();
if (index > 0 && index <= 3) {
break;
}
}
int zan = 0;
for (int i = 0; i < dianZan.length; i++) {
if (i == index - 1) {
zan++;
dianZan[i] += zan;
System.out.println("您为编号 " + index + "菜品点赞成功!");
break;
}
}
System.out.print("是否继续点赞(y/n):");
answer = input.next();
} while (answer.equals("y"));
break;
}
case 6:
default: {
break go;
}
}
System.out.print("\n输入0返回(其他任意键退出系统):");
n = input.next();
} while (n.equals("0"));
System.out.println("谢谢使用,欢迎下次光临!");
}
}
阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

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