java實現(xiàn)簡易外賣訂餐系統(tǒng)
更新時間:2021年10月04日 10:25:07 作者:Вадим
這篇文章主要為大家詳細(xì)介紹了java實現(xiàn)簡易外賣訂餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
用java實現(xiàn)簡易外賣訂餐系統(tǒng),供大家參考,具體內(nèi)容如下
一、使用技術(shù)
javaSE
二、實現(xiàn)功能
外賣訂餐系統(tǒng)
具體要求如下:
使用選擇結(jié)構(gòu),循環(huán)結(jié)構(gòu),數(shù)組的知識實現(xiàn)一個外賣訂餐系統(tǒng)
三、運行效果圖
1.訂餐功能

2.查看餐袋

3.簽收訂單

4.刪除訂單

5.點贊

6.退出

代碼實現(xiàn)
public class Order {
public static void main(String[] args) {
int zero = 1;
int x = 0;//訂單數(shù)組下標(biāo)
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];//點菜份數(shù)
String[] yuDing = new String[100];//訂單狀態(tài)
int a = 0;//點贊數(shù)
int b = 0;//點贊數(shù)
int c = 0;//點贊數(shù)
int panduan = 0;//判斷是否有此訂單
Scanner sc = new Scanner(System.in);
do {
System.out.println("歡迎使用“外賣訂餐系統(tǒng)”");
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.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] = "已預(yù)訂";
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("請選擇您需要的份數(shù):");
menuNum[x] = sc.nextInt();
while (menuNum[x] < 1) {
System.out.println("您輸入的數(shù)量不合法,再次選擇");
menuNum[x] = sc.nextInt();
}
System.out.println("請選輸入送餐時間(送餐時間是10點至20點間整點送餐):");
time[x] = sc.nextInt();
while (time[x] < 10 || time[x] > 20) {
System.out.println("您選擇的時間不在送餐時間內(nèi),再次選擇");
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("序號" + " " + "訂餐人" + " " + "餐品信息"
+ " " + "送餐時間" + " " + "送餐地址"
+ " " + "總金額" + " " + "訂單狀態(tài)");
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);
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot基于JAXB實現(xiàn)天地圖路徑規(guī)劃結(jié)果XML轉(zhuǎn)JSON
這篇文章主要為大家詳細(xì)介紹了SpringBoot如何基于JAXB實現(xiàn)將天地圖路徑規(guī)劃結(jié)果XML轉(zhuǎn)JSON功能,文中的示例代碼講解詳細(xì),需要的可以了解下2025-02-02
使用Jenkins Pipeline自動化構(gòu)建發(fā)布Java項目的方法
這篇文章主要介紹了使用Jenkins Pipeline自動化構(gòu)建發(fā)布Java項目的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04
如何解決websocket開啟多個頁面訪問同一個連接會失效的問題
使用WebSocket時,若多個頁面訪問同一個WebSocket連接可能會導(dǎo)致連接失效,遇到這個問題時,可以通過在SpringBoot中使用@ServerEndpoint注解并添加@Component來解決,出現(xiàn)連接錯誤通常是因為WebSocket連接接收到的是一個GET請求2024-09-09

