java實現簡易外賣訂餐系統
用java實現簡易外賣訂餐系統,供大傢參考,具體內容如下
一、使用技術
javaSE
二、實現功能
外賣訂餐系統
具體要求如下:
使用選擇結構,循環結構,數組的知識實現一個外賣訂餐系統
三、運行效果圖
1.訂餐功能
2.查看餐袋
3.簽收訂單
4.刪除訂單
5.點贊
6.退出
代碼實現
public class Order { public static void main(String[] args) { int zero = 1; int x = 0;//訂單數組下標 String[] name = new String[100]; int[] time = new int[100];//點餐時間 String[] menu = new String[100]; double[] price = new double[100]; int[] od = new int[100];//訂單序號 String[] adress = new String[100];//送餐地址 int[] menuNum = new int[100];//點菜份數 String[] yuDing = new String[100];//訂單狀態 int a = 0;//點贊數 int b = 0;//點贊數 int c = 0;//點贊數 int panduan = 0;//判斷是否有此訂單 Scanner sc = new Scanner(System.in); 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.println("請選擇:"); int num = sc.nextInt(); while (num < 1 || num > 6) { System.out.println("您輸入的選項沒有,重新輸入"); num = sc.nextInt(); } if (num == 1) { od[x] = x + 1; yuDing[x] = "已預訂"; System.out.println("***我要訂餐***"); System.out.println("請輸入訂餐人姓名:"); name[x] = sc.next(); System.out.println("序號" + " " + "菜名" + " " + "單價"); System.out.println(1 + " " + "紅燒茄子" + " " + 24.00); System.out.println(2 + " " + "糖醋排骨" + " " + 36.00); System.out.println(3 + " " + "魚香肉絲" + " " + 32.00); System.out.println("請選擇您想要點的菜品編號:"); int bianHao = sc.nextInt(); while (bianHao < 1 || bianHao > 3) { System.out.println("您選擇的菜品沒有,再次輸入"); bianHao = sc.nextInt(); } if (bianHao == 1) { menu[x] = "紅燒茄子"; price[x] = 24.00; } else if (bianHao == 2) { menu[x] = "糖醋排骨"; price[x] = 36.00; } else if (bianHao == 3) { menu[x] = "魚香肉絲"; price[x] = 32.00; } System.out.println("請選擇您需要的份數:"); menuNum[x] = sc.nextInt(); while (menuNum[x] < 1) { System.out.println("您輸入的數量不合法,再次選擇"); menuNum[x] = sc.nextInt(); } System.out.println("請選輸入送餐時間(送餐時間是10點至20點間整點送餐):"); time[x] = sc.nextInt(); while (time[x] < 10 || time[x] > 20) { System.out.println("您選擇的時間不在送餐時間內,再次選擇"); time[x] = sc.nextInt(); } System.out.println("請輸入送餐地址"); adress[x] = sc.next(); System.out.println("訂餐成功!!!"); System.out.println("您訂的是:" + menu[x] + " " + menuNum[x] + "份"); System.out.println("送餐時間:" + time[x] + "點"); System.out.println("餐費:" + menuNum[x] * price[x] + "元" + " " + "送餐費:6元" + " " + "總計:" + (menuNum[x] * price[x] + 6) + "元"); System.out.println("輸入0返回:"); zero = sc.nextInt(); while (zero != 0) { System.out.println("輸入錯誤,再次輸入"); zero = sc.nextInt(); } x++; } else if (num == 2) { zero = 1; System.out.println("***查看餐帶***"); System.out.println("序號" + " " + "訂餐人" + " " + "餐品信息" + " " + "送餐時間" + " " + "送餐地址" + " " + "總金額" + " " + "訂單狀態"); for (int i = 0; i < x; i++) { if (od[i] != -1) { System.out.println(od[i] + " " + name[i] + " " + menu[i] + " " + time[i] + " " + adress[i] + " " + (menuNum[i] * price[i] + 6) + " " + yuDing[i]); } } System.out.println("輸入0返回:"); zero = sc.nextInt(); while (zero != 0) { System.out.println("輸入錯誤,再次輸入"); zero = sc.nextInt(); } } else if (num == 3) { zero = 1; System.out.println("***簽收訂單***"); System.out.println("請選擇要簽收的訂單的序號:"); int numc = sc.nextInt(); for (int i = 0; i < od.length; i++) { if (numc == od[i]) { yuDing[i] = "已簽收"; System.out.println("訂單簽收成功!"); panduan = 1; } } if (panduan != 1) { System.out.println("無此訂單"); } System.out.println("輸入0返回:"); zero = sc.nextInt(); while (zero != 0) { System.out.println("輸入錯誤,再次輸入"); zero = sc.nextInt(); } } else if (num == 4) { zero = 1; panduan = 0; System.out.println("***刪除訂單***"); System.out.println("請選擇要刪除的訂單的序號:"); int numd = sc.nextInt(); for (int i = 0; i < od.length; i++) { if (numd == od[i]) { od[i] = -1; System.out.println("訂單刪除成功!"); panduan = 1; } } if (panduan != 1) { System.out.println("無此訂單"); } System.out.println("輸入0返回:"); zero = sc.nextInt(); while (zero != 0) { System.out.println("輸入錯誤,再次輸入"); zero = sc.nextInt(); } } else if (num == 5) { zero = 1; System.out.println("***我要點贊***"); System.out.println("序號" + " " + "菜名" + " " + "單價"); System.out.println(1 + " " + "紅燒茄子" + " " + 24.00 + " " + a + "贊"); System.out.println(2 + " " + "糖醋排骨" + " " + 36.00 + " " + b + "贊"); System.out.println(3 + " " + "魚香肉絲" + " " + 32.00 + " " + c + "贊"); System.out.println("請選擇要點贊的菜品的序號:"); int zan = sc.nextInt(); while (zan < 1 || zan > 3) { System.out.println("您輸入的序號錯誤,再次輸入"); zan = sc.nextInt(); } if (zan == 1) { a++; } else if (zan == 2) { b++; } else if (zan == 3) { c++; } System.out.println("輸入0返回:"); zero = sc.nextInt(); while (zero != 0) { System.out.println("輸入錯誤,再次輸入"); zero = sc.nextInt(); } } else if (num == 6) { zero = 1; System.out.println("謝謝使用,歡迎下次光臨!"); return; } } while (zero == 0); } }
以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。
推薦閱讀:
- None Found