订餐系统:
package com.java_2019_1_5;
/*
* 订餐系统
* 陈小锦
*2019-1-5
*/
import java.util.Scanner;
public class DingCan {
public static void main(String[] args) {
Scanner cxj = new Scanner(System.in);
String[] name = {"a","a","a","a"};//订餐者姓名
String[] product = {"红烧鱼","客家豆腐","蛋蒸肉","青菜"};//菜品名
double[] price = {28,12,16,8};//菜品单价
int[] daytime = new int[4];//送餐时间
String[] address = new String[4];//送餐地址
String[] state = new String[4]; //订单状态
int[] zan = {1,5,0,0};
double[] money = new double[4];//总金额
String[] pro = new String[4];//用户选订的菜品名
//name[i]+"\t"+pro[i]+"\t"+daytime[i]+"\t"+address[i]+"\t"+money[i]+"\t"+state[i]
name[0] = "落无上";
pro[0] = "红烧鱼";
daytime[0] = 14;
address[0] = "厦门塘边社";
money[0] = 56;
state[0] = "已完成";
boolean num1 = false,num2 = false,num3 = false,num4 = false,num5 = false,num6 = false;
boolean ver = 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("********************");
System.out.print("请选择:");
int a = cxj.nextInt();
switch(a) {
case 1:
num1 = true;
break;
case 2:
num2 = true;
break;
case 3:
num3 = true;
break;
case 4:
num4 = true;
break;
case 5:
num5 = true;
break;
case 6:
num6 = true;
break;
default:
System.out.println("您的输入有误!请重新输入:");
}
while(num1) {
int ts = 0;
System.out.println("******我要订餐*******");
System.out.println("菜品如下:");
System.out.print("编号\t"+"菜名\t"+"单价\t"+"评价\n");
for(int i = 0;i<product.length;i++) {
System.out.println((i+1)+"\t"+product[i]+"\t"+price[i]+"\t"+zan[i]+"个赞");
}
for(int i=0;i<4;i++) {
if("a".equals(name[i])) {
int t = 0;
System.out.print("请选择:");
int b = cxj.nextInt();
pro[i]= product[b-1];
System.out.print("请输入订餐者姓名:");
name[i] = cxj.next();
System.out.print("请问您需要几份?");
int c = cxj.nextInt();
System.out.print("请输入送餐地址:");
address[i] = cxj.next();
System.out.print("请选择送餐时间(8点到20点整点送餐):");
t = cxj.nextInt();
if(t<8||t>20) {
System.out.print("您的输入有误,请重新输入:");
t = cxj.nextInt();
}else {
daytime[i] = t;
}
money[i] = price[i]*c;
System.out.println("请确认您的信息:");
System.out.println("姓名\t"+name[i]);
System.out.println("餐品信息\t"+pro[i]);
System.out.println("送餐日期\t"+daytime[i]);
System.out.println("送餐地址\t"+address[i]);
System.out.println("总金额\t"+money[i]);
System.out.println("1、确定\t2、取消");
int temp = cxj.nextInt();
if(temp ==1) {
state[i] = "已预定";
System.out.println("马上为您配送!");
break;
}
}else {
ts += 1;
continue;
}
}
if(ts>=4) {
System.out.println("报歉,订单已满!无法订餐!");
}
System.out.println("按0返回:");
int k = cxj.nextInt();
if(k==0) {
ver = true;
num1 = false;
break;
}
}
while(num2) {
System.out.println("******当前餐袋*******");
System.out.println("编号\t姓名\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t订单状态");
for(int i=0;i<4;i++) {
if("a".equals(name[i])) {
break;
}else {
System.out.println((i+1)+"\t"+name[i]+"\t"+pro[i]+"\t\t"+daytime[i]+"点\t\t"+address[i]+"\t"+money[i]+"元\t"+state[i]);
}
}
System.out.println("按0返回:");
int k = cxj.nextInt();
if(k==0) {
ver = true;
num2 = false;
break;
}
}
while(num3) {
int j = 0;
System.out.println("******当前订单*******");
System.out.println("编号\t姓名\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t订单状态");
for(int i=0;i<4;i++) {
if("a".equals(name[i])) {
j = i;
break;
}else {
System.out.println((i+1)+"\t"+name[i]+"\t"+pro[i]+"\t\t"+daytime[i]+"点\t\t"+address[i]+"\t"+money[i]+"元\t"+state[i]);
}
}
if(j==0) {
System.out.println("当前无订单可签收!");
}else {
System.out.print("请输入您要签收的订单编号:");
int r = cxj.nextInt();
if((r-1)>=j) {
System.out.println("无此订单!请重新确认!");
}else {
state[r-1] = "已完成";
System.out.println("签收成功!");
}
}
System.out.println("按0返回:");
int k = cxj.nextInt();
if(k==0) {
ver = true;
num3 = false;
break;
}
}
while(num4) {
int j = 0;
System.out.println("编号\t姓名\t餐品信息\t\t送餐日期\t\t送餐地址\t\t总金额\t订单状态");
for(int i=0;i<4;i++) {
if("a".equals(name[i])) {
j = i;
break;
}else {
System.out.println((i+1)+"\t"+name[i]+"\t"+pro[i]+"\t\t"+daytime[i]+"点\t\t"+address[i]+"\t"+money[i]+"元\t"+state[i]);
}
}
if(j==0) {
System.out.println("当前无订单可删除!");
}else {
System.out.print("请输入您要删除的订单编号:");
int r = cxj.nextInt();
if((r-1)>=j) {
System.out.println("无此订单!请重新确认!");
}else if("已预定".equals(state[r-1])){
System.out.println("此订单未完成,无法删除!请重新确认!");
}else {
name[r-1] = "a";
System.out.println("删除成功!");
}
}
System.out.println("按0返回:");
int k = cxj.nextInt();
if(k==0) {
ver = true;
num4 = false;
break;
}
}
while(num5) {
System.out.println("******我要点赞*******");
System.out.println("菜品如下:");
System.out.print("编号\t"+"菜名\t"+"单价\t"+"评价\n");
for(int i = 0;i<product.length;i++) {
System.out.println((i+1)+"\t"+product[i]+"\t"+price[i]+"\t"+zan[i]+"个赞");
}
System.out.print("请输入菜品编号:");
int j = cxj.nextInt();
zan[j-1]++;
System.out.println("点赞成功!");
System.out.println("按0返回:");
int k = cxj.nextInt();
if(k==0) {
ver = true;
num5 = false;
break;
}
}
while(num6) {
System.out.println("谢谢光临,下次再见!");
ver = false;
num6 = false;
break;
}
}while(ver);
}
}
运行示例:
1、订餐
2、查看餐袋
3、签收订单
4、删除订单
5、菜口点赞
6、退出