标签:今天 img 自己 exit ack cap inf 学java 姓名
咳咳,今天博主给大家写一个小的项目:吃货联盟订餐系统。博主不是大神(互联网架构师的路上ing),也是小白一个,不过是刚入门的小白^_^。项目功能也很简单:只是模拟日常的订餐流程呦,所以有错误以及功能不完善的地方大家多多包涵 O(∩_∩)O哈哈~
首先,先展示下代码功能,代码也不是很多,就200多行!主要功能如下:
用户输入5后,可以进行点赞,输入点赞的序号,进行点赞。返回后可以再次进入进行查看点赞数!!!
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<names.length;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<dishMeg.length;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<names.length;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<names.length;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<names.length;i++){
//判断是否可删除 存在的状态
if(names[i] != null && states[i]==1 && delId==i+1){
//能删除
isDel = true;
for(int j=delId-1;j<names.length-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<dishMeg.length;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("成功退出系统,欢迎下次使用!");
}
}
好啦,今天就到这里,下次继续 。O(∩_∩)O哈哈~
ps:如果有想学Java开发的童鞋或者零基础的,我这里有些Java开发资料,还有Java高级特性和分布式服务等资料,可以相互交流啊!!!
标签:今天 img 自己 exit ack cap inf 学java 姓名
原文地址:https://www.cnblogs.com/sunlll666/p/13169666.html