第十七章作业

一.吃货联盟订餐系统
public class OrderingSet {
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]; //总金额
}
import java.util.Scanner;

public class OrderingUtil{
Scanner input=new Scanner(System.in);
// 供选择的菜品信息
String[] dishNames={“红烧带鱼”,“鱼香肉丝”,“时令蔬菜”};
double[] prices={38.0,20.0,10.0};
int[] praiseNums=new int[3];
OrderingSet oset=new OrderingSet();
public void initisl(){
oset.names[0]=“张晴”;
oset.dishMegs[0]=“红烧带鱼 两份”;
oset.times[0]=12;
oset.addresses[0]=“天成路207号”;
oset.sumPrices[0]=76.0;
oset.states[0]=1;
oset.names[1]=“张晴”;
oset.dishMegs[1]=“鱼香肉丝 两份”;
oset.times[1]=18;
oset.addresses[1]=“天成路207号”;
oset.sumPrices[1]=45.0;
oset.states[1]=0;
}
public void startMenu(){
int num=-1;
boolean isExit=false;
System.out.println("\n欢迎使用“吃货联盟订餐系统”");
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 choose=input.nextInt();
switch(choose){
case 1:
System.out.println(“我要订餐”);
add();
break;
case 2:
System.out.println(“查看餐袋”);
display();
break;
case 3:
System.out.println(“签收订单”);
sign();
break;
case 4:
System.out.println(“删除订单”);
delete();
break;
case 5:
System.out.println(“我要点赞”);
praise();
break;
case 6:
isExit = true;
break;
default:
isExit = true;
break;
}
if(!isExit){
System.out.print(“输入0返回:”);
num=input.nextInt();
}else{
break;
}
}while(num==0);
System.out.println(“欢迎下次光临!”);
}
@SuppressWarnings(“unused”)
boolean add(){
boolean isAdd=false;
for(int a=0;a if(oset.names[a]==null){
isAdd=true;
System.out.print(“请输入订餐人姓名:”);
String name=input.next();
System.out.println(“序号\t菜名\t单价\t点赞数”);
for(int b=0;b String price=prices[b]+“元”;
String priaiseNum=(praiseNums[b])>0?praiseNums[b]+“赞”:“0”;
System.out.println((b+1)+"\t"+dishNames[b]+"\t");
}
System.out.print(“请选择您要点的菜单编号:”);
int chooseDish=input.nextInt();
System.out.print(“请选择您要的份数:”);
int number=input.nextInt();
String dishMeg=dishNames[chooseDish-1]+" “+number+“份”;
double sumPrice=prices[chooseDish-1]*number;
double deliCharge=(sumPrice>=50)?0:5;
System.out.print(“请输入送餐时间(送餐时间是10点至20点间整点送餐):”);
int time=input.nextInt();
while(time>20||time<10){
System.out.println(“您的输入有误,请输入10~20间的整数:”);
time=input.nextInt();
}
System.out.print(“请输入送餐地址:”);
String address=input.next();
System.out.println(“订餐成功!”);
System.out.println(“您订的是:”+dishMeg);
System.out.println(“送餐时间:”+time+“时”);
System.out.println(“餐费:”+sumPrice+“元,送餐费”+deliCharge+“元,总计:”+(sumPrice+deliCharge)+“元。”);
oset.names[a]=name;
oset.dishMegs[a]=dishMeg;
oset.times[a]=time;
oset.addresses[a]=address;
oset.sumPrices[a]=sumPrice+deliCharge;
break;
}
}
if(!isAdd){
System.out.println(“对不起,您的餐袋已满!”);
return false;
}else{
return true;
}
}
@SuppressWarnings(“unused”)
void display(){
System.out.println(“序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t总金额\t订单状态”);
for(int a=0;a if(oset.names[a]!=null){
String state=(oset.states[a]==0)?“已预定”:“已完成”;
String date=oset.times[a]+“时”;
String sumPrice=oset.sumPrices[a]+“元”;
System.out.println((a+1)+”\t"+oset.names[a]+"\t"+oset.dishMegs[a]+"\t"+date+"\t"+oset.addresses[a]+"\t"+sumPrice+"\t"+state);
}
}
}
void sign(){
boolean isSignFind=false;
System.out.print(“请选择要签收的订单号:”);
int signOrderId=input.nextInt();
for(int a=0;a if(oset.names[a]!=null&&oset.states[a]0&&signOrderIda+1){
oset.states[a]=1;
System.out.println(“订单已签收成功!”);
isSignFind=true;
}else if(oset.names[a]!=null&&oset.states[a]1&&signOrderIda+1){
System.out.println(“您选择的订单已完成签收,不能再次签收!”);
isSignFind=true;
}
}
if(!isSignFind){
System.out.println(“您选择的订单不存在!”);
}
}
void delete(){
boolean isDelFind=false;
System.out.print(“请输入要删除的订单序号:”);
int delId=input.nextInt();
for(int a=0;a if(oset.names[a]!=null&&oset.states[a]1&&delIda+1){
isDelFind=true;
for(int b=delId-1;b oset.names[b]=oset.names[b+1];
oset.dishMegs[b]=oset.dishMegs[b+1];
oset.times[b]=oset.times[b+1];
oset.addresses[b]=oset.addresses[b+1];
oset.sumPrices[b]=oset.sumPrices[b+1];
oset.states[b]=oset.states[b+1];
}
int endIndex=oset.names.length-1;
oset.names[endIndex]=null;
oset.dishMegs[endIndex]=null;
oset.times[endIndex]=0;
oset.addresses[endIndex]=null;
oset.sumPrices[endIndex]=0;
oset.states[endIndex]=0;
System.out.println(“删除订单成功!”);
break;
}else if(oset.names[a]!=null&&oset.states[a]0&&delIda+1){
System.out.println(“您的订单为签收,不能删除!”);
isDelFind=true;
break;
}
}
if(!isDelFind){
System.out.println(“该订单不存在!”);
}
}
void praise(){
System.out.println(“序号\t菜名\t单价”);
for(int a=0;a String price=prices[a]+“元”;
String priaiseNum=(praiseNums[a])>0?praiseNums[a]+“赞”:“0”;
System.out.println((a+1)+"\t"+dishNames[a]+"\t"+price+"\t"+priaiseNum);
}
System.out.print(“请选择您要点赞的菜品序号:”);
int priaiseNum=input.nextInt();
praiseNums[priaiseNum-1]++;
System.out.println(“点赞成功!”);
}
}

public class OrderingStart {
public static void main(String[] args) {
OrderingUtil om=new OrderingUtil();
om.initisl();
om.startMenu();
}
}

你可能感兴趣的:(第十七章作业)