package chlm;
import java.util.Scanner;
public class chlm {
public static void main(String[] args) {
//初始化菜品
String meun[] = new String[] {"红烧带鱼","鱼香肉丝","时令鲜蔬"};
double money[] = new double[] {38.0,20.0,10.0};
int zan[] = 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]; // 订单状态: 0:已预定 1:已完成
double[] sumPrices = new double[4]; // 总金额
System.out.println("欢迎使用“吃货联盟订餐系统”");
System.out.println("*****************************");
Scanner sc = new Scanner(System.in);
boolean bool = true;
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.print("请选择:");
int num = sc.nextInt();
if (num == 1) {
System.out.println("***我要订餐***");
System.out.print("请输入订餐人姓名:");
String name = sc.next();
System.out.println("序号"+"\t\t"+"菜名"+"\t\t"+"单价"+"\t\t"+"点赞数");
for (int i = 1; i <= 3; i++) {
System.out.println((i)+"\t\t"+meun[i-1]+"\t\t"+money[i-1]+"\t\t"+zan[i-1]);
}
System.out.println("-----------------------------");
System.out.print("请选择您要点的菜品序号:");
int cai = sc.nextInt();
System.out.print("请选择您需要的份数:");
int fen = sc.nextInt();
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int c = sc.nextInt();
System.out.print("请输入送餐地址:");
String add = sc.next();
System.out.println("-----------------------------");
//保存订单信息
int index = -1;
for (int j = 0; j < names.length; j++) {
if (names[j]==null) {
index = j;
break;
}
}
if (index!=-1) {
String orderMname = meun[cai-1];//获得点菜的菜名
double orderMoney = money[cai-1];//获得单价
double orderMoneySum = orderMoney*fen;//获得总价
double scMoney = 0;//送餐费默认0
names[index] = name;
dishMegs[index] = orderMname+" "+fen+"份";
times[index] = c;
addresses[index] = add;
sumPrices[index] = orderMoneySum;
System.out.println("订餐成功!!!!");
System.out.println("您定的是"+orderMname+" "+fen+"份");
System.out.println("送餐时间是"+c+"点");
System.out.println("餐费:"+orderMoneySum+"元,"+ "送餐费:"+scMoney+"元,总计:"+(orderMoneySum+scMoney));
}else {
System.out.println("下单失败......餐袋已满!!!");
}
System.out.print("请输入0返回:");
int num2 = sc.nextInt();
if(num2 == 0) {
continue;
}
}
if (num == 2) {
System.out.println("***查看餐袋***");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
for (int i = 0; i < names.length; i++) {
if (names[i] != null) {
String state = (states[i]==0)?"已预定":"已完成";
System.out.println((i+1)+"\t\t"+names[i]+"\t\t"+dishMegs[i]+"\t\t"+times[i]+"点"+"\t\t"+addresses[i]+"\t\t"+sumPrices[i]+"元"+"\t\t"+state);
}
}
System.out.print("请输入0返回:");
int num2 = sc.nextInt();
if(num2==0) {
continue;
}
}
if (num == 3) {
System.out.println("***签收订单***");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
int len = 0;
for(int i=0;i<names.length;i++){
if(names[i]!=null){
String state = (states[i]==0)?"已预定":"已完成";
System.out.println((i+1)+"\t\t"+names[i]+"\t\t"+dishMegs[i]+"\t\t"+times[i]+"点"+"\t\t"+addresses[i]+"\t\t"+sumPrices[i]+"元"+"\t\t"+state);
len = i;
}
}
System.out.print("请选择您要签收的订单序号:");
int num3 = sc.nextInt();
if((num3-1)<=len) {
states[num3-1] = 1;
System.out.println("订单签收成功!!!");
}else {
System.out.println("您输入的订单序号不存在!!!");
}
System.out.print("请输入0返回:");
int num2 = sc.nextInt();
if(num2==0) {
continue;
}
}
if (num == 4) {
System.out.println("***删除订单***");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t\t送餐日期\t\t送餐地址\t\t总金额\t\t订单状态");
int len = 0;
for(int i=0;i<names.length;i++){
if(names[i]!=null){
String state = (states[i]==0)?"已预定":"已完成";
System.out.println((i+1)+"\t\t"+names[i]+"\t\t"+dishMegs[i]+"\t\t"+times[i]+"点"+"\t\t"+addresses[i]+"\t\t"+sumPrices[i]+"元"+"\t\t"+state);
}
}
System.out.print("请输入要删除的订单编号:");
int num4 = sc.nextInt();
if(states[num4-1]==1) {
//赋空值
names[num4-1] = null;
dishMegs[num4-1] = null;
times[num4-1] = 0;
addresses[num4-1] = null;
sumPrices[num4-1] = 0;
states[num4-1] = 0;
System.out.println("删除成功!!!");
int index = num4-1;
//删除后,后面的的位置向前填充
for(int i = index;i<(names.length-1);i++) {
names[i] = names[i+1];
dishMegs[i] = dishMegs[i+1];
times[i] = times[i+1] ;
addresses[i] = addresses[i+1] ;
sumPrices[i] = sumPrices[i+1];
states[i] = states[i+1];
}
//清除最后一个的值
names[names.length-1] = null;
dishMegs[names.length-1] = null;
times[names.length-1] = 0;
addresses[names.length-1] = null;
sumPrices[names.length-1] = 0;
System.out.print("请输入0返回:");
int num2 = sc.nextInt();
if(num2==0) {
continue;
}
}else {
System.out.println("您选择的订单未签收,不能删除!!!");
}
}
if (num == 5) {
System.out.println("***我要点赞***");
System.out.println("序号"+"\t\t"+"菜名"+"\t\t"+"单价"+"\t\t"+"点赞数");
for (int i = 1; i <= 3; i++) {
System.out.println((i)+"\t\t"+meun[i-1]+"\t\t"+money[i-1]+"\t\t"+zan[i-1]);
}
System.out.print("请选择您要点赞的菜品序号:");
int cai = sc.nextInt();
zan[cai-1]++;
System.out.println("点赞成功!");
System.out.print("请输入0返回:");
int num2 = sc.nextInt();
if(num2==0) {
continue;
}
}
if (num == 6) {
System.out.println("***谢谢使用,欢迎下次光临!!***");
return;
}
}while(bool);
}
}
Java吃货联盟订餐系统
最新推荐文章于 2024-08-23 15:54:50 发布