import java.util.Scanner;
public class OrderFoods {
public void shom(String[] names, String[] caixinxi, int[] times, String[] adrss, double[] sums,int[] stete, String[] caiName, double[] prices, int[] dz) {
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("====================================");
Scanner sc=new Scanner(System.in);
System.out.println("请输入你的选择");
int a=sc.nextInt();
switch (a){
case 1:
dingCan(names, caixinxi,times, adrss,sums,caiName,prices, dz);
break;
case 2:
Cakan(names,caixinxi,times,adrss,sums,stete);
break;
case 3:
qianshou(names,stete);
break;
case 4:
shabnchu(names,caixinxi,times,adrss,sums,stete );
break;
case 5:
dianzan( caiName, prices, dz);
break;
case 6:
System.exit(0);
default:
System.out.println("你输入的有误,请重新输入");
}
shom(names, caixinxi,times, adrss,sums,stete,caiName,prices, dz);
}
//我要订餐
public void dingCan(String[] names, String[] caixinxi,int[] times,String [] adrss,double[] sums, String[] caiName, double[] prices,int[] dz) {
Scanner sc=new Scanner(System.in);
boolean isadd=false;//判断订单是否已满
for (int i = 0; i <names.length ; i++) {
if(names[i]==null){
//订单未满
isadd=true;
//订餐
System.out.println("请输入订餐人姓名");
String name=sc.next();
System.out.println("序号\t\t菜名\t单价");
//循环输出菜名
for (int j = 0; j <caiName.length ; j++) {
String z=(dz[j]==0)?"":dz[j]+"赞";
System.out.println(j+1+"\t"+caiName[j]+"\t"+prices[j]+"\t"+z);
}
//菜品的编号及判断
System.out.print("请输入你要点的菜品编号");
int bh=sc.nextInt();
while (bh<1||bh>caiName.length){
System.out.print("没有这个编号,请重新输入");
bh=sc.nextInt();
}
//点菜的份数
System.out.println("请输入你需要的份数");
int fs=sc.nextInt();
//送餐时间
System.out.print("请输入你的送餐时间");
int sj=sc.nextInt();
while (sj<10||sj>22) {
System.out.print("这个时间点不营业,请重新输入");
sj = sc.nextInt();
}
//送餐地址
System.out.print("请输入送餐地址:");
String diz=sc.next();
System.out.println("订餐成功");
System.out.println("您定的是"+names[bh-1]+""+fs+"份");//编号减一
System.out.println("送餐时间是"+sj+"点");
//餐费 配送费 总计
double cf=prices[bh-1];//单价
double psf=(cf>30)?0:6;//判断是否要配送费
double zjg=cf+psf;//总费用
System.out.println("餐费:"+cf+"配送费"+psf+"总额"+zjg);
//把订单信息添加到数组
names[i]=name;
caixinxi[i]=names[bh-1]+fs;
times[i]=sj;
adrss[i]=diz;
sums[i]=zjg;
break;
}
}
if(!isadd){
System.out.println("订单已满");
}
}
//查看餐袋
public void Cakan(String[] names,String[] caixinxi,int[] times,String [] adrss,double[] sums,int[] stete ) {
System.out.println("序号\t订餐人\t\t订餐菜品\t\t配送时间\t送餐地址\t\t订餐金额\t订单状态");
for (int i = 0; i <names.length ; i++) {
if(names[i]!=null){
String s=stete[i]==0?"已预订":"已完成";
System.out.println((i+1)+"\t\t"+names[i]+"\t"+caixinxi[i]+"\t\t"+times[i]+"\t\t"+adrss[i]+"\t\t"+sums[i]+"\t"+stete[i]);
}
}
}
//签收订单
public void qianshou(String[] names,int[] stete){
Scanner sc=new Scanner(System.in);
//判断订单是否存在
System.out.println("请输入你要签收的编号");
boolean issing=false;
int a=sc.nextInt();
for (int i = 0; i <names.length ; i++) {
if(names[i]!=null&&stete[i]==0&&i==a-1){
//有订单信息
issing=true;
stete[i]=1;
System.out.println("订单签收成功");
}else if(names[i]!=null&&stete[i]==1&&i==a-1){
issing=true;
System.out.println("订单签收成功,不能重复签收");
}
}
if(!issing){
System.out.println("订单不存在");
}
}
//删除订单
public void shabnchu(String[] names,String[] caixinxi,int[] times,String [] adrss,double[] sums,int[] stete ){
Scanner sc=new Scanner(System.in);
//判断订单是否存在
System.out.println("请输入你要删除的编号");
boolean issing=false;
int a=sc.nextInt();
for (int i = 0; i <names.length ; i++) {
if(names[i]!=null&&stete[i]==0&&i==a-1){
//有订单信息
System.out.println("订单未签收,不能删除");
}else if(names[i]!=null&&stete[i]==1&&i==a-1){
issing=true;
for (int j = i; j <names.length-1 ; j++) {
names[j]=names[j+1];
caixinxi[j]=caixinxi[j+1];
times[j]=times[j+1];
adrss[j]=adrss[j+1];
sums[j]=sums[j+1];
stete[j]=stete[j+1];
}
//换位后最后的元素要置空
names[names.length-1]=null;
caixinxi[caixinxi.length-1]=null;
times[times.length-1]=0;
adrss[adrss.length-1]=null;
sums[sums.length-1]=0;
stete[ stete.length-1]=0;
System.out.println("订单删除成功");
}
}
if(!issing){
System.out.println("订单不存在");
}
}
//点赞
public void dianzan( String[] caiName, double[] prices,int[] dz){
Scanner sc=new Scanner(System.in);
for (int j = 0; j <caiName.length ; j++) {
String z = (dz[j] == 0) ? "" : dz[j] + "赞";
System.out.println(j + 1 + "\t" + caiName[j] + "\t" + prices[j] + "\t" + z);
}
System.out.println("请输入你要点赞的菜品序号");
int a=sc.nextInt();
while (a<1||a>caiName.length){
System.out.println("本店没有这个菜无法点赞,请重新输入");
a=sc.nextInt();
}
dz[a-1]++;
}
}
测试
public class Jiushui {
public static void main(String[] args) {
String[] caiName = {"青椒牛肉", "土豆肉丝", "手撕包菜"};
double[] prices = {18, 12, 10};
int[] dz = new int[3];
//订单
String[] names = new String[4];
String[] caixinxi = new String[4];
int[] times = new int[4];
String[] adrss = new String[4];
double[] sums = new double[4];
int[] stete = new int[4];//0预定1完成订单
//初始化订单
names[0] = "张三";
caixinxi[0] = "青椒牛肉2份";
times[0] = 10;
adrss[0] = "金铂公寓";
sums[0] = 36;
stete[0] = 0;
names[1] = "李四";
caixinxi[1] = "土豆肉丝1份";
times[1] = 10;
adrss[1] = "金铂公寓";
sums[1] = 12;
stete[1] = 0;
OrderFoods o = new OrderFoods();
o.shom(names, caixinxi, times, adrss, sums, stete, caiName, prices, dz);
}
}