用Java实现“吃货联盟订餐系统”
该系统实现的功能:
- 我要订餐
- 查看餐袋
- 签收订单
- 删除订单
- 我要点赞
- 退出系统
package com.xk.test2;
/**
* @xianxin
* 2021-07-17
* test-project
*/
import java.util.Scanner;
public class DemoA {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] foodlist = new String[]{"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};
double[] price = new double[]{38.0, 20.0, 10.0};
//定义的菜品和对应的价格
String[] user = new String[20]; //订餐人姓名
String[] userfood = new String[20];//订的食品名称
int[] foodnum = new int[20]; //食品数量
String[] date = new String[20]; //送餐时间
String[] address = new String[20]; //送餐地址
double[] sum = new double[20]; //价格总计
int[] fabulous = new int[3];//点赞数量
boolean[] sign = new boolean[20];//签收控制信号
for (int i = 0; i < sign.length; i++) {
sign[i] = false;
}//初始化签收控制信号为未签收
for (int i = 0; i < fabulous.length; i++) {
fabulous[i] = 0;
}
int start = 0; //循环控制信号
//测试数据 方便测试
userfood[0] = "鱼香肉丝";
userfood[1] = "鱼香肉丝";
foodnum[0] = 5;
foodnum[1] = 3;
date[0] = "7.17_13:22";
date[1] = "7.17_13:22";
user[0] = "张三";
user[1] = "李四";
address[0] = "西部开源";
address[1] = "西部开源";
sum[0] = 100.0;
sum[1] = 60.0;
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("请选择:");
switch (input.nextInt()) {
case 1:
System.out.println("***我要订餐***");
System.out.print("请输入订餐人姓名:");
String name = input.next(); //获取姓名
System.out.println("序号\t菜品\t单价");
for (int i = 0; i < foodlist.length; i++) {
System.out.println((i + 1) + "\t" + foodlist[i] + "\t" + price[i] + "元");
}
System.out.print("请输入您要点的菜品编号:");
int a = input.nextInt() - 1; //获取菜品编号
System.out.print("请选择您需要的份数:");
int b = input.nextInt(); //获取菜品份数
System.out.print("请输入送餐时间(例如7.17_13:22):");
String time = input.next(); //获取送餐时间
System.out.print("请输入送餐地址:");
String add = input.next(); //获取送餐地址
int tag=0;
for (int i = 0; i < user.length; i++) {
if (user[i] == null) {
user[i] = name;
userfood[i] = foodlist[a]; //把菜品编号对应的菜品存到userfood数组中
foodnum[i] = b;
date[i] = time;
address[i] = add;
sum[i] = price[a] * b;
tag =i;
break;
}
}
System.out.println("订餐成功!");
System.out.println("您订的是:"+userfood[tag]+" "+foodnum[tag]+"份");
System.out.println("送餐时间:"+date[tag]);
System.out.println("餐费:"+sum[tag]+"元,送餐费0.0元,总计:"+sum[tag]+"元。");
System.out.print("输入0返回,输入其他退出:");
start = input.nextInt();
break;
case 2:
if (user[0] == null) {
System.out.println("餐袋为空!");
} else {
System.out.println("***查看餐袋***");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (int i = 0; i < user.length; i++) {
String sn = (sign[i] == false) ? "已预订" : "已完成";
if (user[i] != null) {
System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t"+ date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
}
}
}
System.out.print("输入0返回,输入其他退出:");
start = input.nextInt();
break;
case 3:
if (user[0] == null) {
System.out.println("列表为空不能签收!");
} else {
System.out.println("***签收订单***");
System.out.println("请选择要签收的订单编号:");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (int i = 0; i < user.length; i++) {
String sn = (sign[i] == false) ? "已预订" : "已完成";
if (user[i] != null) {
System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t"+ date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
}
}
int num = input.nextInt() - 1;
sign[num] = true;
System.out.println("订单签收成功!");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (int i = 0; i < user.length; i++) {
String sn = (sign[i] == false) ? "已预订" : "已完成";
if (user[i] != null) {
System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t"+ date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
}
}
System.out.print("输入0返回,输入其他退出:");
start = input.nextInt();
break;
}
case 4:
if (user[0] == null) {
System.out.println("列表为空不能删除!");
} else {
System.out.println("***删除订单***");
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (int i = 0; i < user.length; i++) {
String sn = (sign[i] == false) ? "已预订" : "已完成";
if (user[i] != null) {
System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t"+ date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
}
}
System.out.print("请选择要删除的订单编号:");
int del = input.nextInt() - 1;
if (sign[del] == false) {
System.out.println("您选择的订单未签收,不能删除!");
} else {
user[del] = null;
userfood[del] = null;
foodnum[del] = 0;
date[del] = null;
address[del] = null;
sum[del] = 0;
sign[del] = false;//清空,防止该位为数组最后一位
for (int K = del; K < user.length - 1; K++) {
user[K] = user[K + 1];
userfood[K] = userfood[K + 1];
foodnum[K] = foodnum[K + 1];
date[K] = date[K + 1];
address[K] = address[K + 1];
sum[K] = sum[K + 1];
sign[K] = sign[K + 1];
//从当前位的下一位开始,所有定义的变量全部前移一位
}
System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
for (int i = 0; i < user.length; i++) {
String sn = (sign[i] == false) ? "已预订" : "已完成";
if (user[i] != null) {
System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t"+ date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
}
}
}
}
System.out.print("输入0返回,输入其他退出:");
start = input.nextInt();
break;
case 5:
System.out.println("***我要点赞***");
System.out.println("序号\t 菜品\t\t单价\t\t点赞");
for (int i = 0; i < foodlist.length; i++) {
System.out.println((i + 1) + "\t\t" + foodlist[i] + "\t\t" + price[i] + "元" + "\t\t " + fabulous[i]);
}
System.out.print("请选择您要点赞的菜品序号:");
int fab = input.nextInt() - 1;
fabulous