第一阶段:分析数据主题
第二阶段:分析并完成整体框架
第三阶段:分析并完成退出功能
第四阶段:分析并完成查看餐袋功能
第五阶段:分析并完成订餐功能
第六阶段:分析并完成签收订单功能
第七阶段:分析并完成删除订单功能
第八阶段:分析并完成点赞功能
注意细节:标识位,跳转语句,数组的操作
还有熟练掌握调试技巧
代码过程:
import java.util.*;
public class Work1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] menus= new String[]{"红烧带鱼","鱼香肉丝","时令新蔬"};//菜单
double[] price = new double[] {38,20,10}; //价格
int[] dz = new int[] {0,1,0}; //点赞
String name =null;
int orderIndex = 0;
int orderSecond = 0;
int Time =40;
String address = null;
System.out.println("欢迎使用吃货联盟订餐进餐");
Scanner sc =new Scanner(System.in);
int type = 0;
String []orderName = {"张晴","张晴",null,null,null} ;//订餐人
int []orderDc = {1,2,0,0,0};//菜单
int []orderFl = {2,2,0,0,0};//份
int []orderTime = {3,10,0,0,0};//日期
String []orderAddress = {"天成路","天成路",null,null,null};//地址
String []orderZt = {"已完成","未送达",null,null,null}; //状态
double[] totals = {76,45,0,0,0}; //价格
double total1 = 0;
double total2 = 0;
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.println("请选择: ");
type = sc.nextInt();
switch(type) {
case 1:
//我要订餐
int flag = 1;
for(int i=0;i<orderName.length;i++) {
if(orderName[i]==null) {
flag = 0;
System.out.println("******我要订餐*******");
System.out.println("请输入订单人姓名: ");
name = sc.next();
System.out.println("序号\t"+"菜名\t"+"单价\t"+"点赞");
for(int a=0;a<menus.length;a++) {
System.out.println((a+1)+"\t"+menus[a]+"\t"+price[a]+"\t"+dz[a]);
}
do {
System.out.println("请选择您要点的菜单编号: ");
orderIndex = sc.nextInt();
if(orderIndex>menus.length || orderIndex<0) {
System.out.println("没有这个编号菜单,请重新输入");
continue;
}
}while(orderIndex>menus.length || orderIndex<0);
System.out.println("请选择您需要几份: ");
orderSecond = sc.nextInt();
Time = 40;
do {
System.out.println("请输入送餐时间(送餐时间是10点~20点整点送餐)");
Time = sc.nextInt();
if(Time<10 || Time>20) {
System.out.println("输入送餐时间错误");
continue;
}
}while(Time<10 || Time>20);
total1= price[orderIndex-1]*orderSecond;
total2=total1+6;
System.out.println("请输入送餐地址: ");
address = sc.next();
System.out.println("订餐成功! ");
System.out.println("您订的是: "+menus[orderIndex-1]+orderSecond+"份");
System.out.println("送餐时间: "+Time+"点");
System.out.println("餐费: "+total1+",送餐费6元,总计: "+total2);
for(int k=0;k<orderName.length;k++) {
if(orderName[k]==null) {
orderName[k]=name;
orderDc[k]=orderIndex;
orderFl[k]=orderSecond;
orderTime[k]=Time;
orderAddress[k]=address;
orderZt[k]="未送达";
totals[k]=total1;
break;
}
}
System.out.println("按0返回");
type =sc.nextInt();
break;
}
}
if(flag==1) {
System.out.println("餐袋已经满了,请删除多余餐袋");
System.out.println("按0返回");
type =sc.nextInt();
break;
}
break;
case 2:
//查看餐袋
System.out.println("序号\t"+"订餐人\t"+"所订的餐\t"+"份量\t"+"日期\t"+"送餐地址\t"+"状态\t"+"价格");
for(int i=0;i<orderName.length;i++) {
if(orderName[i]==null) {
break;
}
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderDc[i]-1]+"\t"+orderFl[i]+"\t"
+orderTime[i]+"\t"+orderAddress[i]+"\t"+orderZt[i]+"\t"+totals[i]);
}
System.out.println("按0返回");
type =sc.nextInt();
break;
case 3:
//签收订单
System.out.println("*********签收订单***********");
System.out.println("序号\t"+"订餐人\t"+"所订的餐\t"+"份量\t"+"日期\t"+"送餐地址\t"+"状态\t"+"价格");
for(int i=0;i<orderName.length;i++) {
if(orderName[i]==null) {
break;
}
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderDc[i]-1]+"\t"+orderFl[i]+"\t"
+orderTime[i]+"\t"+orderAddress[i]+"\t"+orderZt[i]+"\t"+totals[i]);
}
do {
System.out.println("请选择签收订单的序号: ");
type=sc.nextInt();
if(type>orderName.length||type<0) {
System.out.println("签收订单号不存在");
continue;
}
}while(type>orderName.length||type<0);
orderZt[type-1]="已完成";
System.out.println("订单签收成功!");
System.out.println("按0返回");
type =sc.nextInt();
break;
case 4:
//删除订单
System.out.println("***********删除订单****************");
System.out.println("序号\t"+"订餐人\t"+"所订的餐\t"+"份量\t"+"日期\t"+"送餐地址\t"+"状态\t"+"价格");
for(int i=0;i<orderName.length;i++) {
if(orderName[i]==null) {
break;
}
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderDc[i]-1]+"\t"+orderFl[i]+"\t"
+orderTime[i]+"\t"+orderAddress[i]+"\t"+orderZt[i]+"\t"+totals[i]);
}
do {
System.out.println("请选输入要删除的订单序号:");
type=sc.nextInt();
if(type>orderName.length||type<0) {
System.out.println("没有这个序号,请重新输入");
continue;
}
}while(type>orderName.length||type<0);
if(orderZt[type-1]=="未送达") {
System.out.println("您选择的订单未签收,不能删除");
}else if(orderZt[type-1]=="已完成"){
System.out.println("删除订单成功");
for(int i=type-1;i<orderName.length-1;i++) {
orderName[i]=orderName[i+1];
orderDc[i]=orderDc[i+1];
orderFl[i]=orderFl[i+1];
orderTime[i]=orderTime[i+1];
orderAddress[i]=orderAddress[i+1];
orderZt[i]=orderZt[i+1];
totals[i]=totals[i+1];
}
orderName[orderName.length-1]=null;
orderDc[orderDc.length-1]=0;
orderFl[orderFl.length-1]=0;
orderTime[orderTime.length-1]=0;
orderAddress[orderAddress.length-1]=null;
orderZt[orderZt.length-1]=null;
totals[totals.length-1]=0;
}else {
System.out.println("没有此订单");
}
System.out.println("按0返回");
type =sc.nextInt();
break;
case 5:
//我要点赞
System.out.println("******我要点赞*******");
System.out.println("序号\t"+"菜名\t"+"单价\t"+"点赞");
for(int i=0;i<menus.length;i++) {
System.out.println((i+1)+"\t"+menus[i]+"\t"+price[i]+"\t"+dz[i]);
}
do {
System.out.println("请输入点赞的序号: ");
type = sc.nextInt();
if(type>menus.length||type<0) {
System.out.println("没有这个序号");
continue;
}
}while(type>menus.length||type<0);
dz[type-1]=dz[type-1]+1;
System.out.println("点赞成功");
System.out.println("按0返回");
type =sc.nextInt();
break;
}
if(type !=6) {
while(type!=0){
System.out.println("输入序号有误");
System.out.print("输入0返回:");
type=sc.nextInt();
}
}
}while(type!=6);
System.out.println("谢谢使用程序");
}
}
以下是输出结果