Java数组 吃货联盟小项目
程序员文章站
2022-04-29 08:57:39
java日记9package orderFood;import java.util.Scanner;/** * @Author Huang * @create 2020/7/16 10:39 */public class OrderFood3 { public static void main(String[] args) { //定义客户信息 String[] names = new String[5]; int[] counts...
java日记9
package orderFood;
import java.util.Scanner;
/**
* @Author Huang
* @create 2020/7/16 10:39
*/
public class OrderFood3 {
public static void main(String[] args) {
//定义客户信息
String[] names = new String[5];
int[] counts = new int[names.length];
String[] phoneNumbers = new String[names.length];
String[] times = new String[names.length];
String[] address = new String[names.length];
boolean[] states = new boolean[names.length];
double[] sumMoney = new double[names.length];
String[] dishName = new String[names.length];
//定义菜品信息
String[] dishes = {"油焖大虾","麻婆豆腐","糖醋里脊","鱼香肉丝","清炒小白菜","酸辣土豆丝"};
double[] prices = {199.99,48.88,67,45,34.0,18.0,16.0};
int[] praise = new int[dishes.length];
Scanner sc = new Scanner(System.in);
//定义主菜单循环条件
String isExit;
//定义主菜单
do{
System.out.println("============欢迎使用吃货联盟在线点餐系统============");
System.out.println("1.我要订餐\t2.查看餐带\t3.签收订单\t4.删除订单\t5.我要点赞\t6.退出系统");
System.out.println("============欢迎使用吃货联盟在线点餐系统============");
System.out.print("请选择需要操作的功能项:");
//选择功能
int choose = sc.nextInt();
switch (choose){
case 1:
//我要订餐功能实现
boolean flag = false;
for(int i=0; i<names.length; i++){
if(names[i]==null){
flag = true;
System.out.println("编号\t\t菜品\t\t单价\t\t点赞数");
for(int j=0; j<dishes.length; j++){
System.out.println((j+1)+"\t\t"+dishes[j]+"\t\t"+prices[j]+"\t\t"+praise[j]);
}
System.out.print("请输入菜品编号:");
int dishNo = sc.nextInt();
while(dishNo<1||dishNo>6){
System.out.print("输入菜品编号有误!请重新输入:");
dishNo = sc.nextInt();
}
System.out.println("您选择的菜品是:"+dishes[dishNo-1]);
System.out.print("请输入菜品份数:");
int count = sc.nextInt();
System.out.print("联系人姓名:");
String name = sc.next();
System.out.print("联系方式:");
String phoneNumber = sc.next();
System.out.print("送餐时间[9:00~22:00]:");
String time = sc.next();
System.out.print("送餐地址:");
String addr = sc.next();
System.out.println("请确认订单信息,确认下单输入ok,输入其他标识取消订单!");
System.out.println("============订单信息如下============");
System.out.println(dishes[dishNo-1]+","+count+"份");
System.out.println(name+"\t"+phoneNumber+"\t"+time+"\t"+addr);
System.out.println("==================================");
String confirm = sc.next();
if(confirm.equalsIgnoreCase("ok")){
dishName[i] = dishes[dishNo-1];
counts[i] = count;
names[i] = name;
phoneNumbers[i] = phoneNumber;
times[i] = time;
address[i] = addr;
sumMoney[i] = prices[dishNo-1]*count>=50?prices[dishNo-1]*count:prices[dishNo-1]*count+5;
System.out.println("订餐成功!请等待送餐~~~");
if(sumMoney[i]>=50){
System.out.println("本订单应支付的餐费是:"+sumMoney[i]+",送餐费:0,合计:"+sumMoney[i]);
}else {
System.out.println("本订单应支付的餐费是:"+prices[dishNo-1]*count+",送餐费:5,合计:"+(sumMoney[i]));
}
}else {
System.out.println("订单已取消~");
break;
}
System.out.println("请记住订单编号:"+(i+1)+"一边后续订单处理~~");
break;
}
}
if(!flag){
System.out.println("订单已满~~抱歉");
}
break;
case 2:
//查看餐袋功能实现
if(!(names[0]==null)){
System.out.println("订单编号\t菜品\t份数\t总金额\t联系人\t联系方式\t送餐时间\t送餐地址\t订单状态");
for(int i=0; i<names.length; i++){
if(names[i]!=null){
System.out.println((i+1)+"\t"+dishName[i]+"\t"+counts[i]+"\t"+sumMoney[i]+"\t"+names[i]+"\t"+phoneNumbers[i]+"\t"+times[i]+"\t"+address[i]+"\t"+(states[i]==false?"未签收":"已签收"));
}
}
}else {
System.out.println("无订单内容!");
}
break;
case 3:
//签收订单功能实现
System.out.println("订单编号\t菜品\t份数\t总金额\t联系人\t联系方式\t送餐时间\t送餐地址\t订单状态");
for(int i=0; i<names.length; i++){
if(names[i]!=null){
System.out.println((i+1)+"\t"+dishName[i]+"\t"+counts[i]+"\t"+sumMoney[i]+"\t"+names[i]+"\t"+phoneNumbers[i]+"\t"+times[i]+"\t"+address[i]+"\t"+(states[i]==false?"未签收":"已签收"));
}
}
if(!(names[0]==null)){
System.out.print("请输入订单编号:");
int stateNo = sc.nextInt();
while(stateNo<1||stateNo>5){
System.out.print("订单编号超出范围,数据不合法...");
System.out.print("请重新输入:");
stateNo = sc.nextInt();
}
for(int i=0; i<names.length; i++){
if(names!=null&&i==stateNo-1&&states[i]==false){
states[i] = true;
System.out.println("订单签收成功!请通过餐袋查看牵手结果~~~");
break;
}else if(names!=null&&i==stateNo-1&&states[i]==true){
System.out.println("订单已经签收过了,不能重复签收!");
break;
}else if(names[i]==null&&i==stateNo-1){
System.out.println("订单编号不存在,无法签收!");
}
}
}else {
System.out.println("无订单内容,无法签收!");
}
break;
case 4:
//删除订单功能实现
System.out.println("订单编号\t菜品\t份数\t总金额\t联系人\t联系方式\t送餐时间\t送餐地址\t订单状态");
for(int i=0; i<names.length; i++){
if(names[i]!=null){
System.out.println((i+1)+"\t"+dishName[i]+"\t"+counts[i]+"\t"+sumMoney[i]+"\t"+names[i]+"\t"+phoneNumbers[i]+"\t"+times[i]+"\t"+address[i]+"\t"+(states[i]==false?"未签收":"已签收"));
}
}
if(!(names[0]==null)){
System.out.print("请输入需要删除的订单编号:");
int delNo = sc.nextInt();
while(delNo<1||delNo>5){
System.out.print("订单编号超出范围,数据不合法...");
System.out.print("请重新输入:");
delNo = sc.nextInt();
}
for(int i=0; i<names.length; i++){
if(names[i]!=null&&i==delNo-1&&states[i]==true){
for(int j=i; j<names.length-1;j++){
names[i] = names[i+1];
dishName[i] = dishName[i+1];
counts[i] = counts[i+1];
sumMoney[i] = sumMoney[i+1];
phoneNumbers[i] = phoneNumbers[i+1];
times[i] = times[i+1];
address[i] = address[i+1];
states[i] = states[i+1];
}
names[names.length-1] = null;
dishName[names.length-1] = null;
counts[names.length-1] = 0;
sumMoney[names.length-1] = 0.0;
phoneNumbers[names.length-1] = null;
times[names.length-1] = null;
address[names.length-1] = null;
states[names.length-1] = false;
System.out.println("订单编号为:"+delNo+"的订单删除成功!可以通过餐袋查看删除结果~~~");
break;
}else if(names[i]!=null&&i==delNo-1&&states[i]==false){
System.out.println("订单未签收,无法删除!");
break;
}else if(names[i]==null&&i==delNo-1){
System.out.println("订单编号不存在,无法删除!");
break;
}
}
}else {
System.out.println("无订单内容,无法删除!");
}
break;
case 5:
//我要点赞功能实现
System.out.println("编号\t\t菜品\t\t单价\t\t点赞数");
for(int j=0; j<dishes.length; j++){
System.out.println((j+1)+"\t\t"+dishes[j]+"\t\t"+prices[j]+"\t\t"+praise[j]);
}
System.out.print("请输入菜品编号:");
int dishNo = sc.nextInt();
if(dishNo>6||dishNo<1){
System.out.println("您选择的菜品不存在,点赞失败!");
}else{
praise[dishNo-1]++;
System.out.println("点赞成功!当前菜品有["+praise[dishNo-1]+"]个赞!");
}
break;
case 6:
//退出系统功能实现
System.out.println("谢谢使用!欢迎下次光临~~~");
System.exit(0);
break;
default:
//选择功能序号有误
System.out.println("输入的选择有误!");
break;
}
System.out.print("输入yes继续使用,输入其他自动退出:");
isExit= sc.next();
}while(isExit.equalsIgnoreCase("yes"));
}
}
吃货联盟个人的小思路~~
本文地址:https://blog.csdn.net/qq_47938500/article/details/107381678