1.程序主页面:
package cn.zhang;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
String[] names = new String[4]; //订餐人姓名 names
String[] Informations = new String[4]; //菜品信息(菜品名称+点菜份数) Informations
int[] times = new int[4]; //送餐时间 times
String[] address = new String[4]; //送餐地址 address
int[] status = new int[4]; //订单状态(0:已预订,1:已完成)status
double[] amounts = new double[4]; //订单总金额 amounts
String[] dishs = {"酸菜鱼" , "红烧排骨" , "番茄炒鸡蛋" , "地锅鸡"}; //菜品名称 dishs
double[] prices = {45.0 , 34.0 , 15.0 , 50.0}; //菜品价格 prices
int[] likes = new int [4]; //菜品点赞数 likes
Scanner sc = new Scanner(System.in); //录入信息
int num = -1; //判断循环,输入0返回
boolean judge = false; //退出系统
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("请选择1-6:");
//选择1
int choose = sc.nextInt();
switch(choose){
//1、我要订餐
case 1:
break;
//2.查看餐袋
case 2:
break;
//3.签收订单
case 3:
break;
//4.删除订单
case 4:
break;
//5、我要点赞
case 5:
break;
//6、退出系统
case 6:
judge = true;
break;
default:
judge = true;
break;
}
if(!judge){
System.out.println("输入0返回主页面");
num = sc.nextInt();
}else {
break;
}
}while(num == 0);
System.out.println("谢谢使用,欢迎下次光临");
sc.close();
}
}
2.我要点餐页面:
//1、我要订餐
case 1:
System.out.println("**我要订餐**");
//判断是否可以订餐 true可以,false不可以
boolean judge1 = false;
//最多4次
for (int i = 0; i < names.length;i++) {
//如果为空则可以添加订单
if(names[i] == null){
//更改judger1为true,使for循环结束后,后面if选择语句不判断
judge1 = true;
System.out.println("*************菜单*************");
System.out.println("序号\t菜名\t单价\t点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price = prices[j] + "元"; //拼接菜品价格
String like = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price + "\t" +like);
}
System.out.print("请选择您要点的菜品编号:");
int dish = sc.nextInt(); //菜品编号 dish = 菜品名称 数组 dishs(数组)
while(dish <= 0 || dish > dishs.length){
System.out.print("请输入正确序列号:");
dish =sc.nextInt();
}
System.out.print("请选择您需要的份数:");
int copies = sc.nextInt(); //点菜份数 copies
System.out.print("请输入订餐人姓名:");
String name = sc.next(); //订餐人姓名 name = 订餐人姓名names(数组)
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int time =sc.nextInt(); //送餐时间 time = 送餐时间 times(数组)
while(time < 10 || time > 20){
System.out.print("你的输入错误!请重新输入10~20之间的整数:");
time =sc.nextInt();
}
System.out.print("请输入送餐地址:");
String addres = sc.next(); //送餐地址 addres = 送餐地址 address(数组)
String Information = dishs[dish-1]+ "," + copies + "份";//菜品信息Information = 菜品信息(菜品名称+点菜份数)Informations(数组)
double amount = prices[dish-1] * copies;//菜品总价(不加配送费):菜对应的价格乘份数的费用
double delivery =(amount >= 50) ? 0 : 6;//送餐费用,大于50不要配送费,小于50要6元配送费。 amount + delivery = 订单总金额 amounts(数组)
System.out.println("订餐成功!");
System.out.println("您预订的是:" + Information );
System.out.println("您的送餐时间是:" + time + "点");
System.out.println("餐费:" + amount + "元,送餐费:" + delivery + " 元,总计:" + (amount + delivery) + "元");
names[i] = name; //订餐人姓名
Informations[i] = Information; //菜品信息(菜品名称+点菜份数)
times[i] = time; //送餐时间
address[i] = addres; //送餐地址
amounts[i] = amount + delivery; //订单总金额
break;
}
}
if(!judge1){
System.out.println("对不起,您的餐袋已经满了!");
}
break;
3. 查看餐袋页面:
//2.查看餐袋
case 2:
System.out.println("**查看餐袋**");
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int i = 0; i < names.length; i++) {
//没有内容不显示
if(names[i] != null){
String time2 = times[i] + "点"; //拼接送餐时间点
String amount2 = amounts[i] + "元"; //拼接总金额元
String statu2 = (status[i] == 0) ? "已预订" : "已完成"; //订单状态int类型默认为0;已预订
System.out.println((i+1) + "\t\t" + names[i] + "\t\t" + Informations[i] + "\t\t" + time2
+ "\t\t" + address[i] + "\t\t" + amount2 + "\t\t" + statu2);
}
}
break;
4. 签收订单页面:
//3.签收订单
case 3:
//选择2
int choose3 = choose;
while(choose3 == 3){
System.out.println("**签收订单**");
//3.无此订单,退出
boolean judge3 = false;
//签收订单前信息页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int i = 0; i < names.length; i++) {
if(names[i] != null){
String time31 = times[i] + "点";
String amount31 = amounts[i] + "元";
String statu31 = (status[i] == 0) ? "已预订" : "已完成";
System.out.println((i+1) + "\t\t" + names[i] + "\t\t" + Informations[i] + "\t\t" + time31
+ "\t\t" + address[i] + "\t\t" + amount31 + "\t\t" + statu31);
}
}
System.out.print("请输入签收订单序列号:");
//订单序列号1
int number = sc.nextInt();
for (int j = 0; j < names.length; j++) {
//数组有内容,订单状态是已预订
if(names[j] != null && status[j] == 0 && number == (j+1)){
status[j] = 1;
System.out.println("订单签收完成");
judge3 = true;
//数组有内容,订单状态是已完成
}else if(names[j] != null && status[j] == 1 && number == (j+1)){
System.out.println("订单已签收无法再次签收");
judge3 = true;
}
}
if(!judge3){
System.out.println("无此订单");
}
//签收订单后信息页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time32 = times[k] + "点";
String amount32 = amounts[k] + "元";
String statu32 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time32
+ "\t\t" + address[k] + "\t\t" + amount32 + "\t\t" + statu32);
}
}
System.out.println("输入3再次签收,输入其他整数退出签收页面");
choose3 = sc.nextInt();
}
break;
5.删除订单页面:
//4.删除订单
case 4:
//选择2
int choose4 = choose;
while(choose4 == 4){
System.out.println("**删除订单**");
//4删除订单退出
boolean judge4 = false;
//删除订单前页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time41 = times[k] + "点";
String amount41 = amounts[k] + "元";
String statu41 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time41
+ "\t\t" + address[k] + "\t\t" + amount41 + "\t\t" + statu41);
}
}
System.out.print("请输入删除订单序列号:");
//订单序列号2
int number2 = sc.nextInt();
for (int i = 0; i < names.length; i++) {
if(names[i] != null && status[i] == 1 && number2 == (i+1)){
for (int j = number2-1; j < names.length-1; j++) {
names[j] = names[j+1]; //订餐人姓名
Informations[j] = Informations[j+1]; //菜品信息(菜品名称+点菜份数)
times[j] = times[j+1]; //送餐时间
address[j] = address[j+1]; //送餐地址
amounts[j] = amounts[j+1]; //订单总金额
status[j] = status [j+1]; //订单状态
}
names[names.length -1] = null; //String
Informations[Informations.length - 1] = null; //String
times[times.length - 1] = 0; //int
address[address.length - 1] = null; //String
amounts[amounts.length - 1] = 0.0; //double
status[status.length - 1] = 0; //int
System.out.println("订单删除成功");
judge4 = true;
break;
}else if(names[i] != null && status[i] == 0 && number2 == (i+1)){
System.out.println("订单未签收,无法删除");
judge4 = true;
break;
}
}
if(!judge4){
System.out.println("无此订单");
}
//删除订单后页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time42 = times[k] + "点";
String amount42 = amounts[k] + "元";
String statu42 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time42
+ "\t\t" + address[k] + "\t\t" + amount42 + "\t\t" + statu42);
}
}
System.out.println("输入4再次删除,输入其他整数退出删除页面");
choose4 = sc.nextInt();
}
break;
6. 我要点赞页面:
//5、我要点赞
case 5:
//选择3
int choose5 = choose;
while(choose5 == 5){
System.out.println("**我要点赞**");
//点赞前菜单
System.out.println("*************菜单*************");
System.out.println("序号"+"\t"+"菜名"+"\t" + "单价" + "\t"+ "点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price51 = prices[j] + "元"; //拼接菜品价格
String like51 = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price51 + "\t" +like51);
}
System.out.println("请输入你要点赞的序列号");
//订单序列号3
int number3 = sc.nextInt();
while(number3 <= 0 || number3 > dishs.length){
System.out.print("请输入正确序列号:");
number3 =sc.nextInt();
}
likes[number3-1]++;
System.out.println("点赞成功");
//点赞后菜单
System.out.println("*************菜单*************");
System.out.println("序号"+"\t"+"菜名"+"\t" + "单价" + "\t"+ "点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price52 = prices[j] + "元"; //拼接菜品价格
String like52 = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price52 + "\t" +like52);
}
System.out.println("输入5再次点赞,输入其他整数退出点赞页面");
choose5 = sc.nextInt();
}
break;
7.退出系统页面:
总代码:
package cn.zhang;
import java.util.Scanner;
public class FoodieAllianceSystem {
public static void main(String[] args) {
String[] names = new String[4]; //订餐人姓名 names
String[] Informations = new String[4]; //菜品信息(菜品名称+点菜份数) Informations
int[] times = new int[4]; //送餐时间 times
String[] address = new String[4]; //送餐地址 address
int[] status = new int[4]; //订单状态(0:已预订,1:已完成)status
double[] amounts = new double[4]; //订单总金额 amounts
String[] dishs = {"酸菜鱼" , "红烧排骨" , "番茄炒鸡蛋" , "地锅鸡"}; //菜品名称 dishs
double[] prices = {45.0 , 34.0 , 15.0 , 50.0}; //菜品价格 prices
int[] likes = new int [4]; //菜品点赞数 likes
Scanner sc = new Scanner(System.in); //录入信息
int num = -1; //判断循环,输入0返回
boolean judge = false; //退出系统
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("请选择1-6:");
//选择1
int choose = sc.nextInt();
switch(choose){
//1、我要订餐
case 1:
System.out.println("**我要订餐**");
//判断是否可以订餐 true可以,false不可以
boolean judge1 = false;
//最多4次
for (int i = 0; i < names.length;i++) {
//如果为空则可以添加订单
if(names[i] == null){
//更改judger1为true,使for循环结束后,后面if选择语句不判断
judge1 = true;
System.out.println("*************菜单*************");
System.out.println("序号\t菜名\t单价\t点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price = prices[j] + "元"; //拼接菜品价格
String like = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price + "\t" +like);
}
System.out.print("请选择您要点的菜品编号:");
int dish = sc.nextInt(); //菜品编号 dish = 菜品名称 数组 dishs(数组)
while(dish <= 0 || dish > dishs.length){
System.out.print("请输入正确序列号:");
dish =sc.nextInt();
}
System.out.print("请选择您需要的份数:");
int copies = sc.nextInt(); //点菜份数 copies
System.out.print("请输入订餐人姓名:");
String name = sc.next(); //订餐人姓名 name = 订餐人姓名names(数组)
System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
int time =sc.nextInt(); //送餐时间 time = 送餐时间 times(数组)
while(time < 10 || time > 20){
System.out.print("你的输入错误!请重新输入10~20之间的整数:");
time =sc.nextInt();
}
System.out.print("请输入送餐地址:");
String addres = sc.next(); //送餐地址 addres = 送餐地址 address(数组)
String Information = dishs[dish-1]+ "," + copies + "份";//菜品信息Information = 菜品信息(菜品名称+点菜份数)Informations(数组)
double amount = prices[dish-1] * copies;//菜品总价(不加配送费):菜对应的价格乘份数的费用
double delivery =(amount >= 50) ? 0 : 6;//送餐费用,大于50不要配送费,小于50要6元配送费。 amount + delivery = 订单总金额 amounts(数组)
System.out.println("订餐成功!");
System.out.println("您预订的是:" + Information );
System.out.println("您的送餐时间是:" + time + "点");
System.out.println("餐费:" + amount + "元,送餐费:" + delivery + " 元,总计:" + (amount + delivery) + "元");
names[i] = name; //订餐人姓名
Informations[i] = Information; //菜品信息(菜品名称+点菜份数)
times[i] = time; //送餐时间
address[i] = addres; //送餐地址
amounts[i] = amount + delivery; //订单总金额
break;
}
}
if(!judge1){
System.out.println("对不起,您的餐袋已经满了!");
}
break;
//2.查看餐袋
case 2:
System.out.println("**查看餐袋**");
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int i = 0; i < names.length; i++) {
//没有内容不显示
if(names[i] != null){
String time2 = times[i] + "点"; //拼接送餐时间点
String amount2 = amounts[i] + "元"; //拼接总金额元
String statu2 = (status[i] == 0) ? "已预订" : "已完成"; //订单状态int类型默认为0;已预订
System.out.println((i+1) + "\t\t" + names[i] + "\t\t" + Informations[i] + "\t\t" + time2
+ "\t\t" + address[i] + "\t\t" + amount2 + "\t\t" + statu2);
}
}
break;
//3.签收订单
case 3:
//选择2
int choose3 = choose;
while(choose3 == 3){
System.out.println("**签收订单**");
//3.无此订单,退出
boolean judge3 = false;
//签收订单前信息页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int i = 0; i < names.length; i++) {
if(names[i] != null){
String time31 = times[i] + "点";
String amount31 = amounts[i] + "元";
String statu31 = (status[i] == 0) ? "已预订" : "已完成";
System.out.println((i+1) + "\t\t" + names[i] + "\t\t" + Informations[i] + "\t\t" + time31
+ "\t\t" + address[i] + "\t\t" + amount31 + "\t\t" + statu31);
}
}
System.out.print("请输入签收订单序列号:");
//订单序列号1
int number = sc.nextInt();
for (int j = 0; j < names.length; j++) {
//数组有内容,订单状态是已预订
if(names[j] != null && status[j] == 0 && number == (j+1)){
status[j] = 1;
System.out.println("订单签收完成");
judge3 = true;
//数组有内容,订单状态是已完成
}else if(names[j] != null && status[j] == 1 && number == (j+1)){
System.out.println("订单已签收无法再次签收");
judge3 = true;
}
}
if(!judge3){
System.out.println("无此订单");
}
//签收订单后信息页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time32 = times[k] + "点";
String amount32 = amounts[k] + "元";
String statu32 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time32
+ "\t\t" + address[k] + "\t\t" + amount32 + "\t\t" + statu32);
}
}
System.out.println("输入3再次签收,输入其他整数退出签收页面");
choose3 = sc.nextInt();
}
break;
//4.删除订单
case 4:
//选择2
int choose4 = choose;
while(choose4 == 4){
System.out.println("**删除订单**");
//4删除订单退出
boolean judge4 = false;
//删除订单前页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time41 = times[k] + "点";
String amount41 = amounts[k] + "元";
String statu41 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time41
+ "\t\t" + address[k] + "\t\t" + amount41 + "\t\t" + statu41);
}
}
System.out.print("请输入删除订单序列号:");
//订单序列号2
int number2 = sc.nextInt();
for (int i = 0; i < names.length; i++) {
if(names[i] != null && status[i] == 1 && number2 == (i+1)){
for (int j = number2-1; j < names.length-1; j++) {
names[j] = names[j+1]; //订餐人姓名
Informations[j] = Informations[j+1]; //菜品信息(菜品名称+点菜份数)
times[j] = times[j+1]; //送餐时间
address[j] = address[j+1]; //送餐地址
amounts[j] = amounts[j+1]; //订单总金额
status[j] = status [j+1]; //订单状态
}
names[names.length -1] = null; //String
Informations[Informations.length - 1] = null; //String
times[times.length - 1] = 0; //int
address[address.length - 1] = null; //String
amounts[amounts.length - 1] = 0.0; //double
status[status.length - 1] = 0; //int
System.out.println("订单删除成功");
judge4 = true;
break;
}else if(names[i] != null && status[i] == 0 && number2 == (i+1)){
System.out.println("订单未签收,无法删除");
judge4 = true;
break;
}
}
if(!judge4){
System.out.println("无此订单");
}
//删除订单后页面
System.out.println("序号\t\t订餐人\t\t菜品信息\t\t送餐时间\t\t送餐地址\t\t订单总金额\t\t订单状态");
for (int k = 0; k < names.length; k++) {
if(names[k] != null){
String time42 = times[k] + "点";
String amount42 = amounts[k] + "元";
String statu42 = (status[k] == 0) ? "已预订" : "已完成";
System.out.println((k+1) + "\t\t" + names[k] + "\t\t" + Informations[k] + "\t\t" + time42
+ "\t\t" + address[k] + "\t\t" + amount42 + "\t\t" + statu42);
}
}
System.out.println("输入4再次删除,输入其他整数退出删除页面");
choose4 = sc.nextInt();
}
break;
//5、我要点赞
case 5:
//选择3
int choose5 = choose;
while(choose5 == 5){
System.out.println("**我要点赞**");
//点赞前菜单
System.out.println("*************菜单*************");
System.out.println("序号"+"\t"+"菜名"+"\t" + "单价" + "\t"+ "点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price51 = prices[j] + "元"; //拼接菜品价格
String like51 = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price51 + "\t" +like51);
}
System.out.println("请输入你要点赞的序列号");
//订单序列号3
int number3 = sc.nextInt();
while(number3 <= 0 || number3 > dishs.length){
System.out.print("请输入正确序列号:");
number3 =sc.nextInt();
}
likes[number3-1]++;
System.out.println("点赞成功");
//点赞后菜单
System.out.println("*************菜单*************");
System.out.println("序号"+"\t"+"菜名"+"\t" + "单价" + "\t"+ "点赞数");//菜品信息(菜品名次、价格、点赞数)
for (int j = 0; j < dishs.length; j++) {
String price52 = prices[j] + "元"; //拼接菜品价格
String like52 = likes[j] > 0 ? likes[j] + "个赞" : " "; //有点赞数就输出值,没有就是空
System.out.println((j+1) + "\t" + dishs[j] + "\t" + price52 + "\t" +like52);
}
System.out.println("输入5再次点赞,输入其他整数退出点赞页面");
choose5 = sc.nextInt();
}
break;
//6、退出系统
case 6:
judge = true;
break;
default:
judge = true;
break;
}
if(!judge){
System.out.println("输入0返回主页面");
num = sc.nextInt();
}else {
break;
}
}while(num == 0);
System.out.println("谢谢使用,欢迎下次光临");
sc.close();
}
}