您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)Java如何實現(xiàn)吃貨聯(lián)盟訂餐系統(tǒng)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
具體內(nèi)容如下
package cn.practice1200; import java.util.Scanner; public class Eater_Alliance { /** * 吃貨聯(lián)盟訂餐系統(tǒng) * * @author QCD * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); // 初始化3個數(shù)組存儲菜品、價格、點贊數(shù) String[] dishNames = { "苦瓜炒雞蛋", "紅燒排骨", "辣子雞丁", "石鍋魚", "麻婆豆腐" }; double[] prices = { 15.0, 30.0, 35.0, 90.0, 20.0 }; int[] praiseNums = new int[5]; // 在初始化6個數(shù)組用于存儲訂單信息 String[] names = new String[5];// 保存訂餐人姓名 String[] dishMegs = new String[5];// 保存所選菜品名 int[] dishNums = new int[5];// 保存所選菜品份數(shù) int[] times = new int[5];// 保存送餐時間 String[] addresses = new String[5];// 保存送餐地址 int[] states = new int[5];// 保存訂單狀態(tài):0表示已預(yù)訂,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] = "建設(shè)路2號"; states[1] = 1; sumPrices[1] = 25.0; /* 實現(xiàn)菜單切換 */ System.out.println("歡迎使用“吃貨聯(lián)盟訂餐系統(tǒng)”"); int num = 1;// 用戶輸入0返回主菜單否則退出系統(tǒng) boolean isExit = false;// 標(biāo)記用戶是否退出系統(tǒng),true為退出 // 循環(huán)控制用戶輸入選擇并執(zhí)行 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、退出系統(tǒng)"); System.out.println("************************"); System.out.print("請選擇:"); num = input.nextInt();// 用戶輸入所要選擇進(jìn)行的操作 /* 使用switch結(jié)構(gòu)來建立選擇內(nèi)容 */ 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" + "點贊數(shù)"); 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("請選擇您需要的份數(shù):"); int number = input.nextInt(); System.out.print("請輸入送餐時間(送餐時間是10點至20點間整點送餐):"); int time = input.nextInt(); while (time < 10 || time > 20) { System.out.print("您的輸入有誤,請輸入10-20間的整數(shù)"); time = input.nextInt(); } System.out.print("請輸入送餐地址:"); String address = input.next(); // 默認(rèn)可以預(yù)定,不用寫訂單狀態(tài) 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) + "元。"); // 添加數(shù)據(jù) 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餐品數(shù)量\t送餐時間\t送餐地址\t總金額\t訂單狀態(tài)"); for (int i = 0; i < names.length; i++) { if (names[i] != null) { String state = (states[i] == 0) ? "已預(yù)訂" : "已完成"; 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;// 標(biāo)記已找到的訂單 } else if (names[i] != null && states[i] == 1 && sign == i + 1) { System.out.println("您選擇的訂單已完成簽收,不能再次簽收!"); isSignFind = true;// 標(biāo)記已找到的訂單 } } 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++) { // 根據(jù)狀態(tà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:// 退出系統(tǒng) isExit = true; break; default:// 退出系統(tǒng) isExit = true; break; } // 返回主界面 if (!isExit) { System.out.print("輸入0返回:"); num = input.nextInt(); } else { break; } } while (num == 0); System.out.println("謝謝惠顧,歡迎您再次使用!"); input.close(); } }
感謝各位的閱讀!關(guān)于“Java如何實現(xiàn)吃貨聯(lián)盟訂餐系統(tǒng)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。