吃货联盟订餐系统
import java.util.*;
public class OrderSystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//菜单数组
String[] menus = {"红烧带鱼","鱼香肉丝","时令鲜蔬"};
double[] prices = {38.0,20.0,10.0};
int[] like = {0,0,0};
//订单数组
String[] orderName = new String[] {"张晴","张晴",null,null,null};//订单人
int[] orderMenu = new int[] {1,2,0,0,0};//菜品名称
int[] orderNums = new int[]{2,2,0,0,0};//份数
int[] orderTime = new int[]{3,10,0,0,0};//送餐日期
String[] orderAddress = new String[] {"天成路207号","天成路207号",null,null,null};//送餐地址
double[] orderTotalPrice = new double[]{76.0,45.0,0,0,0};//总金额
String[] orderState = new String[] {"已完成","已预定",null,null,null};//订单状态
int type = -1;
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("*******************");
System.out.print("请选择: ");
type = input.nextInt();//选择的功能
switch(type) {
case 1:
System.out.println("***我要订餐***");
System.out.print("请输入订餐人姓名:");
String name = input.next();
System.out.println("序号\t菜名\t单价\t点赞数");
for(int i=0;i<menus.length;i++) {
System.out.println((i+1)+"\t"+menus[i]+"\t"+prices[i]+"元"+"\t"+like[i]);
}
//输入订餐信息
System.out.print("请选择您要点的菜品编号:");
int menuIndex = input.nextInt();
System.out.print("请选择您需要的份数:");
int num = input.nextInt();
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int time=input.nextInt();
System.out.print("请输入送餐地址:");
String address = input.next();
System.out.println("订餐成功!");
//保存订单信息
double total = prices[menuIndex-1]*num;
for(int i=0;i<orderName.length;i++) {
if(orderName[i] == null) {
orderName[i] = name;//保存姓名
orderMenu[i] = menuIndex;//保存下单菜品
orderNums[i] = num;//保存订单号
orderTime[i] = time;//保存送餐时间
orderAddress[i] = address;//保存地址
orderState[i] = "已预定";//订单状态初始值
orderTotalPrice[i] = total;//订单总金额
break;
}
}
//打印订餐信息
for(int i=0;i<orderName.length;i++) {
if(orderName[i] != null) {//如果订单里面名字不为空
System.out.println("您订的是:"+menus[menuIndex-1]+orderNums[i]+"份");
System.out.println("送餐时间:"+time+"点");
System.out.println("餐费:"+total+"元,送餐费:0.0元,总计:"+total+"元。");
break;
}
}
break;
case 2:
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) {//如果订单里面名字不为空
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderMenu[i]-1]
+orderNums[i]+"份"+"\t"+orderTime[i]+"\t"+orderAddress[i]+"\t"
+orderState[i]+"\t"+orderTotalPrice[i]);
}
}
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) {//如果订单里面名字不为空
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderMenu[i]-1]
+orderNums[i]+"份"+"\t"+orderTime[i]+"\t"+orderAddress[i]+"\t"
+orderState[i]+"\t"+orderTotalPrice[i]);
}
}
//输入签收的订单号
System.out.print("请输入要签收的订单号:");
int order = input.nextInt();
orderState[order-1] = "已完成";
System.out.println("订单签收成功!");
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) {//如果订单里面名字不为空
System.out.println((i+1)+"\t"+orderName[i]+"\t"+menus[orderMenu[i]-1]
+orderNums[i]+"份"+"\t"+orderTime[i]+"\t"+orderAddress[i]+"\t"
+orderState[i]+"\t"+orderTotalPrice[i]);
}
}
System.out.print("请输入删除的订单号:");
order = input.nextInt();//前面定义过order 这里不用再次定义
for(int i=order-1;i<orderName.length-1;i++) {//数组总长度-1:不然会越界
orderName[i] = orderName[i+1];
orderTime[i] = orderTime[i+1];
orderAddress[i] = orderAddress[i+1];
orderTotalPrice[i] = orderTotalPrice[i+1];
orderState[i] = orderState[i+1];
}
//删除订单后的最后一行设置为null
orderName[orderName.length-1] = null;
orderTime[orderName.length-1] = 0;
orderAddress[orderName.length-1] = null;
orderTotalPrice[orderName.length-1] = 0;
orderState[orderName.length-1] = null;
System.out.println("您选择的订单未签收,不能删除!");
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"+prices[i]+"元\t"+like[i]);
}
System.out.print("请选择您要点赞的菜品序号:");
int menu = input.nextInt();
like[menu-1] = like[menu-1]+1;
System.out.println("点赞成功!");
break;
}
System.out.print("输入0返回:");
type = input.nextInt();
if(type != 0) {//输入0 返回功能页面
break;
}
}while(type !=6);
System.out.println("感谢使用!");
}
}