Java吃货联盟订餐系统代码实例
程序员文章站
2024-02-23 16:48:22
本文实例为大家分享了java订餐系统的具体代码,供大家参考,具体内容如下
package cn.practice1200;
import java.u...
本文实例为大家分享了java订餐系统的具体代码,供大家参考,具体内容如下
package cn.practice1200; import java.util.scanner; public class eater_alliance { /** * 吃货联盟订餐系统 * * @author qcd * @param args */ public static void main(string[] args) { // todo auto-generated method stub scanner input = new scanner(system.in); // 初始化3个数组存储菜品、价格、点赞数 string[] dishnames = { "苦瓜炒鸡蛋", "红烧排骨", "辣子鸡丁", "石锅鱼", "麻婆豆腐" }; double[] prices = { 15.0, 30.0, 35.0, 90.0, 20.0 }; int[] praisenums = new int[5]; // 在初始化6个数组用于存储订单信息 string[] names = new string[5];// 保存订餐人姓名 string[] dishmegs = new string[5];// 保存所选菜品名 int[] dishnums = new int[5];// 保存所选菜品份数 int[] times = new int[5];// 保存送餐时间 string[] addresses = new string[5];// 保存送餐地址 int[] states = new int[5];// 保存订单状态:0表示已预订,1表示已完成 double[] sumprices = new double[5];// 保存订单的总金额 // 初始化2条订单信息 // 第1条 names[0] = "王大锤"; dishmegs[0] = "辣子鸡丁"; dishnums[0] = 2; times[0] = 12; addresses[0] = "莞太路3号"; states[0] = 0; sumprices[0] = 70.0; // 第2条 names[1] = "王大柱"; dishmegs[1] = "麻婆豆腐"; dishnums[1] = 1; times[1] = 19; addresses[1] = "建设路2号"; states[1] = 1; sumprices[1] = 25.0; /* 实现菜单切换 */ system.out.println("欢迎使用“吃货联盟订餐系统”"); int num = 1;// 用户输入0返回主菜单否则退出系统 boolean isexit = false;// 标记用户是否退出系统,true为退出 // 循环控制用户输入选择并执行 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("请选择:"); num = input.nextint();// 用户输入所要选择进行的操作 /* 使用switch结构来建立选择内容 */ switch (num) { case 1:// 我要订餐 system.out.println("***我要订餐***"); boolean isadd = false;// 记录是否可以点餐 for (int i = 0; i < names.length; i++) { if (names[i] == null) { isadd = false; system.out.print("请输入订餐人姓名:"); string name = input.next(); system.out.println("序号" + "\t" + "菜名" + "\t\t" + "单价" + "\t" + "点赞数"); for (int j = 0; j < dishnames.length; j++) { system.out.println( (j + 1) + "\t" + dishnames[j] + "\t\t" + prices[j] + "元" + "\t" + praisenums[j]); } system.out.print("请选择您要点的菜品编号:"); int choosedish = input.nextint(); string dishmeg = dishnames[choosedish - 1]; system.out.print("请选择您需要的份数:"); int number = input.nextint(); system.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):"); int time = input.nextint(); while (time < 10 || time > 20) { system.out.print("您的输入有误,请输入10-20间的整数"); time = input.nextint(); } system.out.print("请输入送餐地址:"); string address = input.next(); // 默认可以预定,不用写订单状态 system.out.println("订餐成功!"); system.out.println("您定的是:" + dishnames[choosedish - 1] + number + "份"); system.out.println("送餐时间:" + time + "点"); double sumprice = prices[choosedish - 1] * number;// 计算餐费 double sendmoney = (sumprice >= 50) ? 0 : 5;// 计算送餐费 system.out.println("餐费:" + sumprice + "元," + "送餐费" + sendmoney + "元," + "总计:" + (sumprice + sendmoney) + "元。"); // 添加数据 names[i] = name; dishmegs[i] = dishmeg; times[i] = time; dishnums[i] = number; addresses[i] = address; sumprices[i] = sumprice + sendmoney; break; } if (isadd) { system.out.println("对不起,您的餐袋已满!"); } } break; case 2:// 查看餐袋 system.out.println("***查看餐袋***"); system.out.println("序号\t订餐人\t餐品名称\t餐品数量\t送餐时间\t送餐地址\t总金额\t订单状态"); for (int i = 0; i < names.length; i++) { if (names[i] != null) { string state = (states[i] == 0) ? "已预订" : "已完成"; system.out.println((i + 1) + "\t" + names[i] + "\t" + dishmegs[i] + "\t" + dishnums[i] + "份" + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumprices[i] + "元" + "\t" + state); } } break; case 3:// 签收订单 system.out.println("***签收订单***"); boolean issignfind = false; system.out.print("请选择要签收的订单序号:"); int sign = input.nextint(); for (int i = 0; i < names.length; i++) { if (names[i] != null && states[i] == 0 && sign == i + 1) { states[i] = 1; system.out.println("订单签收成功!"); issignfind = true;// 标记已找到的订单 } else if (names[i] != null && states[i] == 1 && sign == i + 1) { system.out.println("您选择的订单已完成签收,不能再次签收!"); issignfind = true;// 标记已找到的订单 } } if (!issignfind) { system.out.println("您选择的订单不存在!"); } break; case 4:// 删除订单 system.out.println("***删除订单***"); boolean isdelfind = false; system.out.print("请输入要删除的订单序号:"); int delid = input.nextint(); for (int i = 0; i < names.length; i++) { // 根据状态值判断能不能删除,只有已完成的才能删除 if (names[i] != null && states[i] == 1 && delid == i + 1) { isdelfind = true; for (int j = delid - 1; j < names.length - 1; j++) { names[j] = names[j + 1]; dishmegs[j] = dishmegs[j + 1]; dishnums[j] = dishnums[j + 1]; times[j] = times[j + 1]; addresses[j] = addresses[j + 1]; states[j] = states[j + 1]; sumprices[j] = sumprices[j + 1]; } // 将最后一位清空 names[names.length - 1] = null; dishmegs[names.length - 1] = null; dishnums[names.length - 1] = 0; times[names.length - 1] = 0; addresses[names.length - 1] = null; states[names.length - 1] = 0; sumprices[names.length - 1] = 0; system.out.println("删除订单成功!"); break; } else if (names[i] != null && states[i] == 0 && delid == i + 1) { isdelfind = true; system.out.println("您选择的订单未签收,不能删除!"); break; } } // 未找到的订单不能删除 if (!isdelfind) { system.out.println("您要删除的订单不存在!"); } break; case 5:// 我要点赞 system.out.println("***我要点赞***"); // 显示菜品信息 system.out.println("序号\t菜名\t单价"); for (int i = 0; i < dishnames.length; i++) { string priaisenum = (praisenums[i] > 0) ? praisenums[i] + "赞" : ""; system.out.println((i + 1) + "\t" + dishnames[i] + "\t" + prices[i] + "元" + priaisenum); } system.out.print("请选择您要点赞的菜品序号:"); int number = input.nextint(); praisenums[number - 1]++; system.out.println("点赞成功"); 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("谢谢惠顾,欢迎您再次使用!"); input.close(); } }
以上所述是小编给大家介绍的java订餐系统详解整合,希望对大家有所帮助