吃货联盟点餐系统java代码示例

import java.util.Scanner;


public class Ordering {


/**
* @吃货联盟项目
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
//订单人相关数组
String [] names=new String[4];
int [] times=new int[4];
String [] address=new String[4];
double  [] sumMoney=new double[4];
int [] stateOrder=new int[4];
String [] orderFoods=new String[4];
//菜品相关的数组
int [] praiseNums=new int[4];
String[] foods=new String[4];
double[] foodsPrice=new double[4];
//初始化菜品信息
foods[0]="红烧刀鱼";
foodsPrice[0]=20.0;
praiseNums[0]=0;

foods[1]="鱼香肉丝";
foodsPrice[1]=30;
praiseNums[1]=0;

foods[2]="时令鲜蔬";
foodsPrice[2]=35.5;
praiseNums[2]=0;
//初始化订单信息
names[0]="张晴";
orderFoods[0]="红烧刀鱼2份";
times[0]=12;
address[0]="三好街20号";
stateOrder[0]=1;
sumMoney[0]=40.0;

names[1]="张晴";
orderFoods[1]="鱼香肉丝2份";
times[1]=18;
address[1]="三好街20号";
stateOrder[1]=0;
sumMoney[1]=60.0;

boolean reback=true;
do{
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("7.退出系统");
System.out.println("*******************");
System.out.println("请选择");
int choose=input.nextInt();
switch (choose) {
case 1:
System.out.println("***我要订餐***");
System.out.println("序号\t菜品名称\t价格\t点赞数");
for (int i = 0; i < foodsPrice.length; i++) {
if(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+foods[i]+"\t"+foodsPrice[i]+"\t"+praiseNums[i]);
}
}
System.out.println("请输入订餐人姓名");
String nameIn=input.next();
if(nameIn!=null&&!"".equals(nameIn)){
System.out.println("请输入订购菜品序号");
int num1=input.nextInt();
System.out.println("请输入分数");
int num2=input.nextInt();
double totalPrice=foodsPrice[num1-1]*num2;
if(totalPrice<50){
totalPrice=totalPrice+5;
}
System.out.println("请输入送餐时间");
int time=input.nextInt();
System.out.println("请输入送餐地址");
String addressIn=input.next();
int index=-1;
for (int i = 0; i < names.length; i++) {
if(null==names[i]||"".equals(names[i])){
index=i;
break;
}
}
if(index!=-1){
names[index]=nameIn;
orderFoods[index]=foods[num1-1]+num2+"份";
times[index]=time;
address[index]=addressIn;
stateOrder[index]=0;
sumMoney[index]=totalPrice;
}
System.out.println("订餐成功");
}else{
System.out.println("订餐人姓名不能为空");
}
System.out.println("是否继续Y/N");
String anwser =input.next();
if("y".equalsIgnoreCase(anwser)){
reback=true;
continue;
}
reback=false;
break;
case 2:
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t产品信息\t\t送餐时间\t送餐地址\t总金额\t订单状态");
for(int i=0;iif(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+names[i]+"\t"+orderFoods[i]+"\t\t"+times[i]+"\t"+address[i]+"\t"+sumMoney[i]+"\t"+(stateOrder[i]==0?"已预订":"已完成"));
}
}
System.out.println("是否继续Y/N");
anwser =input.next();
if("y".equalsIgnoreCase(anwser)){
reback=true;
continue;
}
reback=false;
break;
case 3:
System.out.println("***签收订单***");
System.out.println("请选择要签收的订单序号");
int oedernum=input.nextInt();
stateOrder[oedernum-1]=1;
System.out.println("签收成功");
System.out.println("是否继续Y/N");
anwser =input.next();
if("y".equalsIgnoreCase(anwser)){
reback=true;
continue;
}
reback=false;
break;
case 4:
System.out.println("***删除订单***");
System.out.println("请输入要删除的订单序号");
int deleteNum=input.nextInt();
if(stateOrder[deleteNum-1]==0){
System.out.println("订单状态预订不能删除");
}else{
for (int i = deleteNum-1; i < names.length-1; i++) {
names[i]=names[i+1];
orderFoods[i]=orderFoods[i+1];
times[i]=times[i+1];
address[i]=address[i+1];
stateOrder[i]=stateOrder[i+1];
sumMoney[i]=sumMoney[i+1];
}
names[names.length-1]=null;
orderFoods[names.length-1]=null;
times[names.length-1]=0;
address[names.length-1]=null;
stateOrder[names.length-1]=0;
sumMoney[names.length-1]=0;
System.out.println("删除订单成功~");
}
System.out.println("是否继续Y/N");
anwser =input.next();
if("y".equalsIgnoreCase(anwser)){
reback=true;
continue;
}
reback=false;
break;
case 5:
System.out.println("***我要点赞***");
System.out.println("序号\t菜品名称\t价格\t点赞数");
for (int i = 0; i < foodsPrice.length; i++) {
if(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+foods[i]+"\t"+foodsPrice[i]+"\t"+praiseNums[i]);
}
}
System.out.println("请输入要点赞的菜品序号");
int foodsNum=input.nextInt();
praiseNums[foodsNum-1]+=1;
System.out.println("点赞成功");
System.out.println("序号\t菜品名称\t价格\t点赞数");
for (int i = 0; i < foodsPrice.length; i++) {
if(names[i]!=null&&!"".equals(names[i].trim())){
System.out.println((i+1)+"\t"+foods[i]+"\t"+foodsPrice[i]+"\t"+praiseNums[i]);
}
}
System.out.println("是否继续Y/N");
anwser =input.next();
if("y".equalsIgnoreCase(anwser)){
reback=true;
continue;
}
reback=false;
break;
case 6:
System.out.println("***添加菜单***");
int addIndex=-1;
for(int i=0;iif(foods[i]!=null&&"".equals(foods[i])){
addIndex=i;
break;
}
}
if(addIndex!=-1){
System.out.println("请输入添加菜品的名称:");
String newFoods=input.next();
System.out.println("请输入新菜品的价格");
double newPrice=input.nextDouble();

foods[addIndex]=newFoods;
foodsPrice[addIndex]=newPrice;
praiseNums[addIndex]=0;
}else{
System.out.println("菜单已满,部门添加~");
}
break;
case 7:
System.out.println("***退出系统***");
reback=false;
break;


default:
System.out.println("输入错误,请从新输入~");
reback=true;
break;
}
}while(reback);
}


}

你可能感兴趣的:(Java基础,数组应用,java基础项目)