java小白“吃货联盟订餐系统“

java小白“吃货联盟订餐系统“,第1张

java小白“吃货联盟订餐系统“
public class mainSystem {

	public static void main(String[] args) {
		// 订餐系统
		// 1.数据初始化,使用数组来存储菜品信息和订单信息
		// 菜品信息包括菜品名称/菜品单价/点赞数量
		String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };// 菜品名称
		double[] prices = { 38, 20, 10 };// 菜品单价
		int[] praiseNums = new int[3];// 点赞数
		// 订单信息包括订餐人/送餐时间/送餐地点/菜品信息/订单状态/总金额
		String[] names = new String[4];// 订餐人
		int[] times = new int[4];// 送餐时间
		String[] addresses = new String[4];// 送餐地点
		String[] dishMegs = new String[4];// 菜品信息
		int[] states = new int[4];// 订单状态
		double[] sumPrices = new double[4];// 总金额
		Scanner sc = new Scanner(System.in);
		// 判断是否退出系统的开关
		boolean unexit = true;
		do {
			System.out.println("欢迎使用"吃货联盟订餐系统"");
			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("请选择: ");
			//必须放在这个位置,已对应下一句
			 sc = new Scanner(System.in);
			if(sc.hasNextInt()!=true) {
				System.out.println("输入非法字符,请重新选择!");
				continue;
			}
			int choice = sc.nextInt();
			
			switch (choice) {
			case 1: // 我要订餐
				System.out.println("***我要订餐***");
				// 判断餐袋是否已满的开关
				boolean full = true;
				for (int i = 0; i < names.length; i++) {
					// 找到餐袋未满的位置,进行点餐
					if (names[i] == null) {
						full = false;
						System.out.print("请输入订餐人姓名: ");
						String name = sc.next();
						// 打印菜单
						System.out.println("序号t菜名t单价t点赞数");
						for (int j = 0; j < dishNames.length; j++) {
							System.out.println(j + 1 + "t" + dishNames[j] + "t" + prices[j] + "元t"
									+ (praiseNums[j] > 0 ? praiseNums[j] + "赞" : "0"));
						}
						System.out.print("请选择你要的菜单编号: ");
						int choooseDish = sc.nextInt();
						System.out.print("请选择您需要的份数: ");
						int num = sc.nextInt();
						double sumPrice = prices[choooseDish - 1] * num;
						// 送餐费
						double fee = sumPrice >= 50 ? 0 : 5;
						System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送) : ");
						int time = sc.nextInt();
						while (time < 10 || time > 20) {
							System.out.println("你输入的有误,请输入10点至20点的整数!");
							time = sc.nextInt();
						}
						System.out.print("请输入送餐地址: ");
						String address = sc.next();
						System.out.println("订餐成功!");
						names[i] = name;
						times[i] = time;
						addresses[i] = address;
						dishMegs[i] = dishNames[choooseDish - 1] + num + "份";
						sumPrices[i] = sumPrice + fee;
						System.out.println("您订的是: " + dishMegs[i]);
						System.out.println("送餐时间: " + times[i] + "点");
						System.out.println("餐费: " + sumPrice + "元, 送餐费" + fee + "元, 总计: " + sumPrices[i] + "元");
						break;
					}
				}
				if (full) {
					System.out.println("对不起,您的餐袋已满!");
				}
				break;
			case 2:// 查看餐袋
				System.out.println("***查看餐袋***");
				System.out.println("序号t订餐人t餐品信息tt送餐时间t送餐地址tt总金额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" + times[i] + "点t"
								+ addresses[i] + "tt" + sumPrices[i] + "t" + state);
					}
				}
				break;
			case 3:// 签收订单
				System.out.println("***签收订单***");
				System.out.print("请选择要签收的订单序号: ");
				int signNum = sc.nextInt();
				// 判断订单是否存在
				boolean check = true;
				for (int i = 0; i < names.length; i++) {
					if (names[i] != null && states[i] == 0 && signNum == i + 1) {
						states[i] = 1;
						System.out.println("订单签收成功!");
						check = false;
						break;
					} else if (names[i] != null && states[i] == 1 && signNum == i + 1) {
						System.out.println("订单已签收,不能重复签收!");
						check = false;
						break;
					}
				}
				if (check) {
					System.out.println("您选择的订单不存在!");
				}
				break;
			case 4:
				System.out.println("***删除订单***");
				System.out.print("请选择您要删除的订单序号: ");
				int delNum = sc.nextInt();
				boolean check2 = true;
				for (int i = 0; i < names.length; i++) {
					if (names[i] != null && states[i] == 1 && delNum == i + 1) {
						check2 = false;
						for (int j = delNum-1; j < sumPrices.length-1; j++) {
							names[j] = names[j + 1];
							times[j] = times[j + 1];
							addresses[j] = addresses[j + 1];
							dishMegs[j] = dishMegs[j + 1];
							states[j] = states[j + 1];
							sumPrices[j] = sumPrices[j + 1];
						}
						// 最后的位置清空
						names[names.length - 1] = null;
						times[times.length - 1] = 0;
						addresses[addresses.length - 1] = null;
						dishMegs[dishMegs.length - 1] = null;
						states[states.length - 1] = 0;
						sumPrices[sumPrices.length - 1] = 0;
						System.out.println("订单删除成功!");
						break;
					} else if (names[i] != null && states[i] == 0 && delNum == i + 1) {
						check2 = false;
						System.out.println("您选的订单未签收,不能删除");
						break;
					}

				}
				if (check2) {
					System.out.println("你要删除的订单不存在!");
				}
				break;
			case 5:
				System.out.println("***我要点赞***");
				System.out.println("序号t菜名t单价t");
				for (int j = 0; j < dishNames.length; j++) {
					System.out.println(j + 1 + "t" + dishNames[j] + "t" + prices[j] + "t"
							+ (praiseNums[j] > 0 ? praiseNums[j] + "赞" : ""));
				}
				System.out.print("请选择您要点赞的菜品序号: ");
				int praiseNum = sc.nextInt();
				praiseNums[praiseNum - 1]++;
				System.out.println("点赞成功!");
				break;
			case 6:
				unexit = false;
				break;
			}
			if (unexit) {
				System.out.print("输入0返回:");
				int num = sc.nextInt();
				
				if (num != 0) {
					break;
				}
			}
		} while (unexit);
		sc.close();
		System.out.println("谢谢使用,欢迎下次光临!");
	}

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5575536.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存