当前位置:网站首页>One of the small practical projects - food alliance ordering system
One of the small practical projects - food alliance ordering system
2022-07-31 07:08:00 【Weak crown original intention】
系统概述:
- 我要订餐
- 查看餐袋
- 签收订单
- 删除订单
- 我要点赞
- 退出系统

下面是实例代码:
import java.util.Scanner;
public class OrderFoodSys {
public static void main(String[] args) {
// Define the data subject:订单 菜品
String[] dishNames ={"红烧带鱼","鱼香肉丝","时令蔬菜"};//菜品名称
double[] prices = {38.0,20.0,10.0};//The unit price of the dish
int[] praiseNums = new int[3];//点赞数
// Define the data subject: 订单-订餐人 餐品信息 送餐时间 送餐地址 总金额 订单状态
String[] names = new String[4];
String[] dishMsg = new String[4];//菜品名称+number of copies
int[] times = new int[4];
String[] adresses = new String[4];
double[] sumPrices = new double[4];
int[] states = new int[4];//0:已预定 1:已完成
// 初始化2个订单信息
names[0]="张三";
dishMsg[0]="红烧带鱼 2份";
times[0]=10;
adresses[0]="知春路223号";
sumPrices[0]=76;//餐费》50免费送,不然,配送费6元
states[0]=0;
names[1]="李四";
dishMsg[1]="鱼香肉丝 1份";
times[1]=13;
adresses[1]="天成路207号";
sumPrices[1]=26;//餐费》50免费送,不然,配送费6元
states[1]=1;
// Build the overall process framework of the project
Scanner input = new Scanner(System.in);
int num = -1;//用户输入0The input number on return,num=0The main menu is displayed repeatedly;numPrompt for re-assignment after each ordering operation of the user
// System.out.println("欢迎使用“吃货联盟订餐系统”");
System.out.println("欢迎使用\"Foodie alliance system\"");
boolean flag=false;//ture 退出 flase 不退出
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.print("请选择:");
int choose = input.nextInt();
switch(choose){
case 1:
System.out.println("\n******我要订餐***********");
//The premise of the order is that the order is not full,booleanvariable to identify the result of whether the order is full,满了falseNot available for order
boolean isAdd = false;
for (int i = 0; i < names.length; i++) {
if(names[i]==null){
//订单未满,可以订餐
isAdd = true;
//订餐.
System.out.print("请输入订餐人姓名:");
String name = input.next();
//Loop output dish information
System.out.println("序号\t菜品\t单价");
for(int j =0;j<dishNames.length;j++){
String praise =(praiseNums[j]==0)?"":praiseNums[j]+"赞";
System.out.println((j+1)+"\t"+dishNames[j]+"\t"+prices[j]+"\t"+praise);
}
//Input and judgment of dish number
System.out.print("请输入您要点的菜品编号:");
int no = input.nextInt();
while(no<1||no>dishNames.length){
System.out.print("This restaurant does not have this dish,请重新选择:");
no=input.nextInt();
}
//Number of servings
System.out.print("Please enter the number of copies you want:");
int number = input.nextInt();
//Input and judgment of meal delivery time
System.out.print("请输入送餐时间(Meal delivery hours are only available10-20the whole point in between):");
int time = input.nextInt();
while(time <10|| time>20){
System.out.println("您输入有误,请输入10-20之间的整数:");
time = input.nextInt();
}
//送餐地址
System.out.print("请输入送餐地址:");
String address = input.next();
//added to the order,Output order information to the user
System.out.println("订餐成功!");
//菜品信息:菜品名称 份数
String dishInfo = dishNames[no-1]+" "+number+"份";
System.out.println("您订的是:"+dishInfo);
System.out.println("送餐时间:"+time+"点");
//餐费 配送费 总计
//餐费 prices数组下标 than the user chooses The number of dishes is small1
double dishPrice = prices[no-1]*number;
double peiSong = (dishPrice>50)?0:6;
double sumPrice = dishPrice +peiSong;
System.out.println("餐费:"+dishPrice+"元; 配送费:"+peiSong+";总计:"+sumPrice+"元");
//Add order information to order information,Where the order is inserted is key:i
names[i]=name;
dishMsg[i]=dishInfo;
times[i]=time;
adresses[i]=address;
sumPrices[i]=sumPrice;
//
break;
}
}
if(!isAdd){
System.out.println("对不起,您的餐袋已满!");
}
break;
case 2:
System.out.println("\n******查看餐袋***********");
System.out.println("序号\t订餐人\tOrder food\t\t配送时间\t配送地址\t\tOrder amount\t订单状态");
for (int i = 0; i < names.length; i++) {
if(names[i]!=null){
String time = times[i]+"点";
String state = (states[i]==0)?"已预定":"已完成";
System.out.println((i+1)+"\t"+names[i]+"\t"+dishMsg[i]+"\t"+time+"\t"+adresses[i]+"\t"+sumPrices[i]+"\t"+state);
}
}
break;
case 3:
System.out.println("\n******签收订单***********");
//before signing,First determine whether the order exists,boolean
//false 不存在,Can not sign:true-存在,and predetermined status,Can sign;存在,完成状态,Can not sign
boolean isSign = false;
System.out.println("Enter the order number you want to sign for:");
int signNo = input.nextInt();
for(int i = 0;i<names.length;i++){
if(names[i]!=null&&states[i]==0&&i==signNo-1){
//有订单信息,And the order number entered by the user I can find
isSign = true;
//And the order status is booked,Can sign
states[i]=1;
System.out.println("订单签收成功!");
}
else if(names[i]!=null&&states[i]==1 && i==signNo-1){
//有订单信息,And the order number entered by the user I can find
isSign=true;
//But the order status is completed,Can not sign
System.out.println("您选择的订单已经完成签收,不能再次签收!");
}
}
if(!isSign){
System.out.println("您选择的订单不存在!");
}
break;
case 4:
System.out.println("\n******删除订单***********");
//删除之前,First determine whether the order exists,boolean
//false 不存在,不能删除:true-存在,and predetermined status,不能删除;存在,完成状态,能删除
boolean isDelete = false;
System.out.print("Enter the order number you want to delete:");
int deleteNo = input.nextInt();
for(int i = 0;i<names.length;i++){
if(names[i]!=null&&states[i]==0&&i==deleteNo-1){
//有订单信息,And the order number entered by the user I can find
isDelete = true;
//And the order status is booked,不能删除
System.out.println("您选择的订单未签收,不能删除!");
}
else if(names[i]!=null && states[i]==1 && i==deleteNo-1){
//有订单信息,And the order number entered by the user I can find
isDelete=true;
//But the order status is completed,能删除
//Find the delete order position subscripti,把iSubsequent elements move forward accordingly,最后一个元素置空
//注意:The process of moving is actually the process of copying the next element to the previous element
//The last element must be left blank,Leave empty to place a new order
for (int j = i; j < names.length-1; j++) {
names[j]=names[j+1];
dishMsg[j]=dishMsg[j+1];
times[j]=times[j+1];
adresses[j]=adresses[j+1];
sumPrices[j]=sumPrices[j+1];
states[j]=states[j+1];
}
names[names.length-1]=null;
dishMsg[names.length-1]=null;
times[names.length-1]=0;
adresses[names.length-1]=null;
sumPrices[names.length-1]=0;
states[names.length-1]=0;
System.out.println("删除订单成功!");
}
}
if(!isDelete){
System.out.println("您选择的订单不存在!");
}
break;
case 5:
System.out.println("\n******我要点赞***********");
//Loop output dish information
System.out.println("序号\t菜名\t单价");
for (int j = 0; j < dishNames.length; j++) {
String praise=(praiseNums[j]==0)?"":praiseNums[j]+"赞";
System.out.println((j+1)+"\t"+dishNames[j]+"\t"+praise);
}
//点赞
System.out.println("请输入您要点赞的菜品序号:");
int praiseNo= input.nextInt();
while(praiseNo<1||praiseNo>dishNames.length){
System.out.print("This restaurant does not have this dish,Can't like!Please re-enter a dish number:");
praiseNo = input.nextInt();
}
//关键点:Add the number of likes to the dishes at that location1
praiseNums[praiseNo-1]++;
break;
case 6:
flag = true;
break;
default:
flag = true;
break;
}
if(!flag){//!flag 等同于 flag==false
System.out.print("请输入0返回:");
num = input.nextInt();
}else{
break;
}
}while(num==0);
System.out.println("谢谢使用,欢迎下次光临!");
}
}
边栏推荐
猜你喜欢
随机推荐
Database Principles Homework 3 — JMU
机器学习反向传播的一些推导公式
小实战项目之——吃货联盟订餐系统
文本三剑客之e`grep,seq文本编辑工具
DDL+DML+DQL
进程和计划任务管理
shell之条件语句(test、if、case)
Moment.js常用方法
Oracle入门 10 - Linux 设备类型与文件目录结构
Third-party library-store
cp 的用法
Analysis of the principle and implementation of waterfall flow layout
(border-box) The difference between box model w3c and IE
PXE高效批量网络装机
接口报错no message avaliable
服务器硬件及RAID配置实战
NFS共享存储服务
2022.7.29 数组
Run the NPM will pop up to ask "how are you going to open this file?"
【云原生】3.3 Kubernetes 中间件部署实战









