今天给大家一个小的项目:吃货联盟订餐系统。项目功能也很简单:只是模拟日常的订餐流程呦,所以有错误以及功能不完善的地方大家多多包涵 O(∩_∩)O哈哈~
首先,先展示下代码功能,代码也不是很多,就200多行!主要功能如下:
首先进入系统后,是菜单的展示:
用户输入选择,并对输入的选择进行判断,如果有误,就退出系统!
用户输入1后,进行点餐,并输入点餐人姓名,以及点的份数和时间、地址,会自动计算出费用返回给用户。
用户输入2后,可以查看餐袋,发现自己点的订单已在餐袋中
用户输入3后,可以签收订单,如果订单是已预订状态,可以进行签收;如果是已完成状态,不能签收订单;否则提示用户找不到订单信息,不能签收!
用户输入4后,可以对订单进行删除。如果订单是已预订状态,不能删除;如果是已完成状态,可以删除;否则提示用户找不到订单,不能删除!
用户输入5后,可以进行点赞,输入点赞的序号,进行点赞。返回后可以再次进入进行查看点赞数!!!
用户输入6后,退出系统!!!
package cn.kgc.sg.Demo;
import java.util.*;
public class DingCanSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String names[] = new String[4]; //姓名
String dishMsg[] = new String[4]; //菜品信息
int times[] = new int[4]; //送餐时间
String address[] = new String[4]; //送餐地址
int states[] =new int[4]; //订单状态 0:已完成 1:已预订
double sumPrices[] = new double[4]; //订单总金额
names[0] = "孙港";
dishMsg[0] = "玉米";
times[0] = 12;
address[0] = "柏悦澜庭";
states[0] = 1;
sumPrices[0] = 100;
names[1] = "王玥";
dishMsg[1] = "大米";
times[1] = 14;
address[1] = "中博校区";
states[1] = 0;
sumPrices[1] = 200;
System.out.println("欢迎光临吃货联盟订餐系统》》》》》》》");
System.out.println("**************************");
/**
* 定义并初始化菜单信息
*/
String dishMeg[] = {"西红柿炒鸡蛋","火锅牛肉","泡椒凤爪"};
double prices[] ={58,99,36};
int [] zan =new int[4];
boolean isExit = false; //false 不退出系统
int nums = -4; //随意赋值
do{
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.print("请输入您的选择: ");
int choose = sc.nextInt();
boolean isAdd =false; //false 是不能点餐
boolean isFind = false ;//false 不能找到订单编号
boolean isDel = false; //false 不能删除
switch(choose){
case 1:
System.out.println("*****我要订餐*****");
for(int i = 0;i
if(names[i] == null){
isAdd = true;
System.out.print("请输入订餐人的姓名:");
String name = sc.next();
//遍历菜单信息
System.out.println("序号"+"\t\t"+"菜单"+"\t\t"+"单价"+"\t\t"+"点赞数");
for(int j = 0 ;j
String yuan = prices[j]+"元";
System.out.println((j+1)+"\t\t"+dishMeg[j]+"\t\t"+yuan+"\t\t"+zan[j]);
}
System.out.print("请输入订餐的编号:");
int bianhao = sc.nextInt();
String dishName = dishMeg[bianhao-1];
System.out.print("请输入订餐的份数:");
int fen = sc.nextInt();
double p=prices[bianhao-1];
double sumPrice = p*fen;
int ptf = sumPrice>50 ? 0 : 6;
System.out.print("请输入订餐时间(营业时间在10-20点):");
int time = sc.nextInt();
while(time<10 || time>20){
System.out.print("请在营业时间内订餐(10-20点),请重新输入:");
time = sc.nextInt();
}
System.out.print("请输入送餐地址:");
String dizhi = sc.next();
System.out.println(".............订餐成功...........");
System.out.println("您订的是:"+dishName+" ,"+fen+"份!");
System.out.println("餐费是:"+sumPrice+",送餐费是:"+ptf+"元,合计:"+(sumPrice+ptf)+"元!");
//将对应的值存到数组中
names[i]=name;
times[i]=time;
address[i]=dizhi;
dishMsg[i]= dishName; //dishMeg
sumPrices[i]=(sumPrice+ptf);
break;
}
}
if(!isAdd){
System.out.println("sorry,餐袋已满,不能点餐!!!");
}
break;
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
if(names[i] != null){
String time = times[i]+"时";
String price = sumPrices[i]+"元";
String state=states[i]== 1 ? "已完成" : "已预订";
System.out.println((i+1)+"\t\t"+names[i]+"\t\t"+dishMsg[i]+"\t\t"+time+
"\t\t"+address[i]+"\t\t"+price+"\t\t"+state);
}
}
break;
case 3:
System.out.println("***********签收订单**********");
System.out.print("请选择要签收的编号:");
int orderId = sc.nextInt();
for(int i=0;i
if(names[i] != null && states[i]==0 && orderId == i+1){
//可以签收
states[i]=1;
isFind = true;
System.out.println("订单签收成功!");
break;
}else if(names[i] != null && states[i]==1 && orderId == i+1){
//不能签收
isFind = true;
System.out.println("订单不能签收!");
break;
}
}
if(!isFind){
System.out.println("输入的订单号有误!!!");
}
break;
case 4:
System.out.println("*********删除订单*********");
System.out.print("请输入删除的订单编号:");
int delId = sc.nextInt();
//循环遍历数组
for(int i = 0;i
//判断是否可删除 存在的状态
if(names[i] != null && states[i]==1 && delId==i+1){
//能删除
isDel = true;
for(int j=delId-1;j
names[j]=names[j+1];
times[j]=times[j+1];
dishMsg[j]=dishMsg[j+1];
address[j]=address[j+1];
sumPrices[j]=sumPrices[j+1];
states[j]=states[j+1];
}
System.out.println("已完成的订单已被删除!!!");
//将最后一个位置置空
names[names.length-1] = null;
times[names.length-1] = 0;
dishMsg[names.length-1] = null;
address[names.length-1] = null;
sumPrices[names.length-1] = 0;
states[names.length-1] = 0;
break;
}else if(names[i] != null && states[i]==0 && delId==i+1) {
//不能删除
isDel = true;
System.out.println("订单未完成,不能删除!!!");
}
}
if(!isDel){
System.out.println("您输入的订单号有误!!!");
}
break;
case 5:
System.out.println("******我要点赞******");
System.out.println("序号"+"\t\t"+"菜单"+"\t\t"+"单价"+"\t\t"+"点赞数");
for(int j = 0 ;j
String yuan = prices[j]+"元";
System.out.println((j+1)+"\t\t"+dishMeg[j]+"\t\t"+yuan+"\t\t"+zan[j]);
}
System.out.print("请输入您要点赞的序号:");
int num = sc.nextInt();
zan[num-1]=zan[num-1]+999;
System.out.println("恭喜您点赞成功!!!");
break;
case 6:
isExit = true;
break;
default:
isExit = true;
}
if(!isExit){
System.out.print("输入0返回!(请再次输入):");
nums = sc.nextInt();
}else{
break;
}
}while(nums == 0);
System.out.println("成功退出系统,欢迎下次使用!");
}
}
喜欢前端、后端java开发的可以加+qun:609565759,有详细视频、资料、教程,文档,值得拥有!!!希望可以一起努力,加油ヾ(◍°∇°◍)ノ゙!!!
B站有上传的更多项目视频,从Java基础到面向对象、Java高级API,以及SSM等框架的视频,地址:https://www.bilibili.com/video/BV15a411w7Jh