吃货联盟订餐系统初始代码,基本实现初步功能,后续功能有待更新和优化,请各位看官不吝指点!!!!!
代码:
import java.util.Scanner;
public class DingCan {
// private static final String[] String = null;
public static void main(String[] args) {
/*
* 初始化num0,num0=0时返回系统界面, flag标志为flag时退出整个系统,即为选项6的功能
*/
int num0 = -1;
boolean flag = true;
// 创建信息数组
/*
* xuhao 订单序号
* names 客户姓名
* menu 菜品名
* count 份数
* time 送餐时间
* address 送餐地址
* moneys 总金额
* state 订单状态
* MeHao 菜单序号
* menus 菜单
* Price 菜单单价
* Zan 菜品点赞数
*/
int[] XuHao = new int[4];
String[] names = new String[4];
String[] menu = new String[4];
int[] count = new int[4];
int[] time = new int[4];
String[] address = new String[4];
double[] moneys = new double[4];
String[] state = new String[4];
String[] menus = {"红烧带鱼","鱼香肉丝","时令鲜疏"};
double[] Price = {38.0,15.0,10.0};
int[] Zan = {55,46,20};
int[] MeHao = {1,2,3};
// 初始化两个餐袋信息
XuHao[0] = 1;
names[0] = "张三";
menu[0] = "红烧带鱼";
count[0] = 2;
time[0] = 12;
address[0] = "天成路207号";
moneys[0] = 76.0;
state[0] = "已预订";
XuHao[1] = 2;
names[1] = "李四";
menu[1] = "鱼香肉丝";
count[1] = 2;
time[1] = 18;
address[1] = "天成路207号";
moneys[1] = 30.0;
state[1] = "已完成";
// 循环订餐系统
do {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
System.out.println("欢迎使用“吃货联盟订餐系统!”");
// 显示操作界面
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.println("请选择:");
int choose = input.nextInt();
switch(choose) {
// 1、我要订餐
case 1:
System.out.println("****我要订餐****");
for(int i=0;i<XuHao.length;i++) {
if(names[i]==null) {
System.out.print("请输入订餐人姓名:");
XuHao[i]=i+1;
names[i]=input.next();
System.out.println("序号\t\t菜名\t\t单价\t\t点赞数\t\t");
for(int i1 = 0;i1<menus.length;i1++) {
System.out.println(MeHao[i1]+"\t\t"+menus[i1]+"\t\t"+Price[i1]+"元\t\t"+Zan[i1]);
}
boolean flag1 = false;
System.out.print("请选择您要点的菜单编号:");
int dex;
do {
dex = input.nextInt();
if(dex>=1&&dex<=3) {
break;
}else {
System.out.print("您选择的菜单编号不存在,请重新选择:");
flag1 = true;
}
}while(flag1);
menu[i] = menus[dex-1];
System.out.print("请输入您需要的分数:");
int num = input.nextInt();
count[i] = num;
moneys[i] = Price[dex-1]*num;
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
do {
time[i] = input.nextInt();
if(time[i]>=10&&time[i]<=20) {
break;
}else {
flag1 = true;
System.out.print("您输入的时间不在送餐时间内,请重新输入(送餐时间是10点至20点间整点送餐):");
}
}while(flag1);
System.out.print("请输入您的送餐地址:");
address[i] = input.next();
state[i] = "已预订";
System.out.println("恭喜您订餐成功!订单详情如下:");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
System.out.println(XuHao[i]+"\t\t"+names[i]+"\t\t"+menu[i]+"\t\t"+count[i]+
"份\t\t"+time[i]+"点\t\t"+address[i]+"\t\t"+moneys[i]+"\t\t"+state[i]);
break;
}else if(i == XuHao.length-1){
System.out.println("对不起,目前餐袋已满,无法订餐,请稍后再订餐,谢谢!");
}
}
break;
// 2、查看餐袋
case 2:
System.out.println("****查看餐袋****");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
for(int i=0;i<XuHao.length;i++) {
if(names[i]==null) {
break;
}else {
System.out.println(XuHao[i]+"\t\t"+names[i]+"\t\t"+menu[i]+"\t\t"+count[i]+
"份\t\t"+time[i]+"点\t\t"+address[i]+"\t\t"+moneys[i]+"\t\t"+state[i]);
}
}
break;
// 3、签收订单
case 3:
boolean flag1 = true;
System.out.println("****签收订单****");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
for(int i=0;i<XuHao.length;i++) {
if(names[i]==null) {
break;
}else {
System.out.println(XuHao[i]+"\t\t"+names[i]+"\t\t"+menu[i]+"\t\t"+count[i]+
"份\t\t"+time[i]+"点\t\t"+address[i]+"\t\t"+moneys[i]+"\t\t"+state[i]);
}
}
do {
System.out.println("请选择要签收的订单序号:");
int num = input.nextInt();
if(state[num-1] == "已完成") {
System.out.println("该订单已完成,无法重复签收,请重新选择需要签收的订单序号!");
}else {
flag1 = false;
state[num-1] = "已完成";
System.out.println("订单签收成功!");
break;
}
}while(flag1);
break;
// 4、删除订单
case 4:
boolean flag11 = true;
System.out.println("****删除订单****");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
for(int i=0;i<XuHao.length;i++) {
if(names[i]==null) {
break;
}else {
System.out.println(XuHao[i]+"\t\t"+names[i]+"\t\t"+menu[i]+"\t\t"+count[i]+
"份\t\t"+time[i]+"点\t\t"+address[i]+"\t\t"+moneys[1]+"\t\t"+state[i]);
}
}
do {
System.out.println("请选择您需要删除的订单序号:");
int num = input.nextInt();
if(names[num-1] == null) {
System.out.println("该订单序号不存在,请重新选择您要删除的订单序号!");
}else {
flag11 = false;
for(int i = num;i<XuHao.length;i++) {
XuHao[i-1] = XuHao[i]-1;
names[i-1] = names[i];
menu[i-1] = menu[i];
count[i-1] = count[i];
time[i-1] = time[i];
address[i-1] = address[i];
moneys[i-1] = moneys[i];
state[i-1] = state[i];
}
System.out.println("订单删除成功!");
System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
for(int i=0;i<XuHao.length;i++) {
if(names[i]==null) {
break;
}else {
System.out.println(XuHao[i]+"\t\t"+names[i]+"\t\t"+menu[i]+"\t\t"+count[i]+
"份\t\t"+time[i]+"点\t\t"+address[i]+"\t\t"+moneys[1]+"\t\t"+state[i]);
}
}
break;
}
}while(flag11);
break;
// 5、我要点赞
case 5:
boolean flag2 = true;
System.out.println("****我要点赞****");
System.out.println("序号\t\t菜名\t\t单价\t\t点赞数\t\t");
for(int i = 0;i<menus.length;i++) {
System.out.println(MeHao[i]+"\t\t"+menus[i]+"\t\t"+Price[i]+"元\t\t"+Zan[i]);
}
do{
System.out.println("请选择您要点赞的菜品序号:");
int i = input.nextInt();
if(i<=MeHao.length) {
flag2 = false;
Zan[i-1]+=1;
System.out.println("点赞成功!");
break;
}else {
System.out.println("您选择的菜品序号不存在,请重新选择!:");
}
}while(flag2);
System.out.println("****我要点赞****");
System.out.println("序号\t\t菜名\t\t单价\t\t点赞数\t\t");
for(int i = 0;i<menus.length;i++) {
System.out.println(MeHao[i]+"\t\t"+menus[i]+"\t\t"+Price[i]+"元\t\t"+Zan[i]);
}
break;
// 6、退出系统
case 6:
System.out.println("****退出系统****");
flag= false;
break;
default:
// 客户输入0~6以外的数字皆默认不使用本系统
flag= false;
break;
}
if(!flag==true) {
break;
}else {
System.out.println("请输入0返回菜单");
num0 = input.nextInt();
}
}while(num0==0);
System.out.println("谢谢使用,欢迎下次光临!");
}
}
各个功能运行结果:
1、订餐功能
2、查看餐袋
3、签收订单
4、删除订单
5、我要点赞
6、退出系统以及输入其他数字默认不使用本系统