Java实现简单订餐系统
本文实例为大家分享了Java实现简单订餐系统的具体代码,供大家参考,具体内容如下
import java.util.Scanner; import java.util.*; public class OrderingMsg { public static void main(String[] args) { // 数据主体:一组订单信息 String[] names = new String[4]; // 订餐人名称 String[] dishMegs = new String[4]; // 所选菜品 int[] times = new int[4]; // 送餐时间 String[] addresses = new String[4]; // 送餐地址 int[] states = new int[4]; // 订单状态: 0:已预定 1:已完成 double[] sumPrices = new double[4]; // 总金额 //初始化2个订单信息 names[0] = "张晴"; dishMegs[0] = "红烧带鱼 2份"; times[0] = 12; addresses[0] = "天成路207号"; sumPrices[0] = 76.0; states[0] = 1; names[1] = "张晴"; dishMegs[1] = "鱼香肉丝 2份"; times[1] = 18; addresses[1] = "天成路207号"; sumPrices[1] = 20.0; // 供选择的菜品信息 String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" }; // 菜品名称 double[] prices = new double[] { 38.0, 20.0, 10.0 }; // 菜品单价 int[] praiseNums = new int[3]; Scanner input = new Scanner(System.in); int num = -1; // 用户输入0返回主菜单,否则退出系统 boolean isExit = false; // 标志用户是否退出系统: true:退出系统 System.out.println("\n欢迎使用“吃货联盟订餐系统”"); // 循环:显示菜单,根据用户选择的数字执行相应功能 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(); // 记录用户选择的功能编号 boolean isAdd = false; //记录是否可以订餐 boolean isSignFind = false; //找到要签收的订单 boolean isDelFind = false; //找到要删除的订单 // 根据用户选择的功能编号执行相应功能 switch (choose) { case 1: // 我要订餐 System.out.println("***我要订餐***"); System.out.print("请输入订餐人姓名:"); String name=input.next(); isAdd=true; int j = 0; for (; j < names.length; j++) { //todo if(names[j]==null){ names[j]=name; break; } else { isAdd=true; } } if(!isAdd){ System.out.println("对不起,您的餐袋已满!"); } else { System.out.println("序号"+"\t"+"菜品名"+"\t"+"价格"); for(int i=0;i<dishNames.length;i++){ System.out.print(i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\n"); } System.out.print("请输入菜品编号:"); int dishNum=input.nextInt(); System.out.print("请输入菜品数量:"); int dishCnt=input.nextInt(); String dishMeg=dishNames[dishNum-1]+dishCnt+"份"; dishMegs[j]=dishMeg; System.out.print("请输入收货地址:"); String Addr=input.next(); addresses[j]=Addr; System.out.print("请输入收货时间:"); int time=input.nextInt(); times[j]=time; double sumPrice=prices[dishNum-1]*dishCnt; double deliCharge=(sumPrice>50)?0:5; System.out.println("餐费:"+sumPrice+"元,送餐费:"+deliCharge+"元,总计:"+(sumPrice+deliCharge)+"元。"); sumPrices[j]=sumPrice+deliCharge; } break; case 2: // 查看餐袋 System.out.println("***查看餐袋***"); System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态"); //todo for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"已完成":"已预定"; System.out.print((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 3: // 签收定单 System.out.println("***签收定单***"); //todo System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态"); for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"已完成":"已预定"; System.out.print((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } System.out.print("请选择要签收的订单序号:"); int n=input.nextInt(); states[n-1]=1; System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态"); for(int i=0;names[i]!=null;i++) { String sta=(states[i]==1)?"已完成":"已预定"; System.out.print((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 4: // 删除订单 System.out.println("***删除订单***"); System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态"); for(int i=0;i<4;i++) { String sta=(states[i]==1)?"已完成":"已预定"; System.out.print((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } System.out.print("请输入要删除的订单序号:"); //todo int m=input.nextInt(); for(int k=m; k<4;k++) { names[k-1]=names[k]; dishMegs[k-1]=dishMegs[k]; times[k-1]=times[k]; addresses[k-1]=addresses[k]; sumPrices[k-1]=sumPrices[k]; states[k-1]=states[k]; } System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态"); for(int i=0;i<4;i++) { String sta=(states[i]==1)?"已完成":"已预定"; System.out.print((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t"+times[i]+"\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+sta+"\n"); } break; case 5: // 我要点赞 System.out.println("***我要点赞***"); // 显示菜品信息 System.out.println("序号" + "\t" + "菜名"+"\t"+"单价"); for(int i=0;i<dishNames.length;i++){ System.out.print(i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\t"+praiseNums[i]+"赞"+"\n"); } //todo System.out.print("请输入点赞序号:"); int number=input.nextInt(); praiseNums[number-1]=praiseNums[number-1]+1; System.out.println("序号" + "\t" + "菜名"+"\t"+"单价"); for(int i=0;i<dishNames.length;i++){ System.out.print(i+1+"\t"+dishNames[i]+"\t"+prices[i]+"\t"+praiseNums[i]+"赞"+"\n"); } break; case 6: // 退出系统 isExit = true; break; default: //退出系统 isExit = true; break; } if (!isExit) { System.out.print("输入0返回:"); num = input.nextInt(); } else { break; } } while (num == 0); System.out.println("谢谢使用,欢迎下次光临!"); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)