溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何使用Java實現(xiàn)簡單點餐系統(tǒng)

發(fā)布時間:2022-01-26 09:00:11 來源:億速云 閱讀:146 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下如何使用Java實現(xiàn)簡單點餐系統(tǒng),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

程序控制分析:

1、歡迎頁循環(huán):do-while
2、Scanner 控制輸入
3、選擇頁循環(huán):switch-case

要求:

訂單信息:String 二維數(shù)組
序號、姓名、餐品名稱、份數(shù)、價格、總價、地址、時間(10-20)、狀態(tài)(已預(yù)定、已完成)、熱度(int型)

簽收訂單:改變訂單狀態(tài),已預(yù)定可以簽收,如果已經(jīng)完成則不能再次簽收。

刪除訂單:不能刪除未完成訂單,序號要隨之改變。

我要點贊:對相應(yīng)的餐品點贊,并展示。

package Practice;

import java.util.Scanner;

public class Obj {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String dishes[]={"紅燒肉","燒熊掌","清蒸魚","白斬雞","烤乳鴿"};
        int price[]={58,88,45,56,44};
        int honors[]={50,100,20,12,44};
        int hot[]={5,4,3,2,0};
        String orders[][]=new String[1024][];

        int chose=0;
        System.out. println("歡迎關(guān)嶺紅浪漫餐廳");
        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.println("請選擇:");
            chose=sc.nextInt();
//訂餐流程-------------------------------------------------------------------------------------
            switch (chose) {

                case 1:
                    System.out.println("***我要訂餐***");
                    System.out.println("請輸入訂餐人姓名:");
                    String name=sc.next();

                    System.out.println("序號     菜品    單價   熱度");
                    for (int i = 0; i < dishes.length; i++) {
                        System.out.println(i+1+"\t\t"+dishes[i]+"\t"+price[i]+"元\t"+"\t"+hot[i]);
                    }

                    int dishNum=0;
                    do{
                        System.out.println("菜品編號");
                        dishNum=sc.nextInt();
                        if ((dishNum<1||dishNum>dishes.length)){
                            System.out.println("對不起,輸入有誤,請重新輸入!");
                        }
                    }while (dishNum<1||dishNum>dishes.length);

                    int pcs=0;
                    do {
                        System.out.println("份數(shù)");
                        pcs=sc.nextInt();
                        if (pcs<1){
                            System.out.println("對不起,輸入有誤,請重新輸入!");
                        }
                    }while (pcs<1);


                    int time;
                    do {
                        System.out.println("送餐時間");
                        time=sc.nextInt();
                        if (time<10||time>22){
                            System.out.println("對不起,輸入有誤,請重新輸入!");
                        }
                    }while (time<10||time>22);

                    System.out.println("地址");
                    String addres=sc.next();

                    System.out.println("success!");
                    System.out.println(
                            "您定的商品信息是:" +dishes[dishNum]+ "\t" +dishNum+"份");
                    System.out.println("送餐時間為"+time);

                    double cost=price[dishNum-1]*pcs;
                    double sent=cost>50?0:6;
                    double total=cost+sent;
                    System.out.println("餐費共計"+total+" 其中快遞費"+sent+"元");

                    for (int i = 0; i < orders.length; i++) {
                        if (orders[i]==null){
                            orders[i]=new String[3];
                            orders[i][0]=name+"\t"+dishes[dishNum-1]+"\t"
                                    +pcs+"份\t"+time+"\t"+addres+"\t"+cost+"元";  //orders第一存儲 菜品信息
                            orders[i][1]="已預(yù)定";                      //orders第二存儲 訂單信息
                            break;
                        }
                    }

                    break;
//查看餐袋------------------------------------------------------------------------------
                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序號\t訂餐人  餐品信息 時間 地址 總金額    訂單狀態(tài)");
                    for (int i = 0; i < orders.length; i++) {
                        if (orders[i]!=null){
                            System.out.println(i+1+"\t"+orders[i][0]+"\t\t"+orders[i][1]);
                        }else{
                            break;
                        }
                    }
                    break;
//訂單簽收----------------------------------------------------------------------------
                case 3:
                    System.out.println("***簽收訂單***");
                    int num;
                    int end=0;
                    System.out.println("序號\t訂餐人  餐品信息 時間 地址 總金額    訂單狀態(tài)");
                    for (int i = 0; i < orders.length; i++) {
                        if (orders[i]!=null){
                            System.out.println(i+1+"\t"+orders[i][0]+"\t\t"+orders[i][1]);
                        }else{
                            break;
                        }
                    }

                    do {
                        System.out.println("請輸入要簽收訂單序號:");
                        for (int i = 0; i < orders.length; i++) {
                            if (orders[i]==null){
                                end=i+1;
                                break;
                            }
                        }

                        num=sc.nextInt();

                        if (num<0||num>end){
                            System.out.println("輸入有誤");
                        }else if ("已預(yù)定".equals(orders[num-1][1])){
                            orders[num-1][1]="已完成";
                            System.out.println("訂單已完成");
                            break;
                        }else{
                            System.out.println("訂單已簽收,不能重復(fù)簽收");
                            break;
                        }

                    }while (num<1||num>end||"已預(yù)定".equals(orders[num-1][1]));

                    break;
//刪除訂單------------------------------------------------------------------------
                case 4:
                    System.out.println("***刪除訂單***");
                    int n=0;   //輸入數(shù)字
                    int e=0;  // 訂單的最大數(shù)量
                    System.out.println("序號\t訂餐人 \t餐品信息 \t送餐時間 \t地址 \t總金額 \t狀態(tài)");
                    for (int i = 0; i < orders.length; i++) {
                        if (orders[i]!=null){
                            System.out.print(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]+"\t");
                            System.out.println("\t  "+orders[i][1]);
                        }else{
                            break;
                        }
                    }


                    do {
                        for (int i = 0; i < orders.length; i++) {        //確定訂單的最大數(shù)量
                            if (orders[i]==null){
                                e=i;
                                break;
                            }
                        }

                        System.out.println("要刪除的訂單編號:");
                        n=sc.nextInt();
                    if (n<1||n>e){
                        System.out.println("err");
                    }else if ( ! "已完成".equals(orders[n-1][1])){
                        System.out.println("訂單未完成,不能刪除");
                        break;
                    }else{
                        boolean isDelete=false;
                        for (int i = n-1; i < orders.length; i++) {
                            if (i==orders.length-1){
                                orders[i]=null;
                                isDelete=true;          //
                            }else{
                                orders[i]=orders[i+1];   //前移
                                if (orders[i]==null){
                                    isDelete=true;
                                    break;
                                }
                            }
                        }
                    }
                    }while (n<1||n>e||"已完成".equals(orders[n][1]));

                    break;
//我要點贊----------------------------------------------------------------------------
                case 5:
                    System.out.println("***我要點贊***");
                    int hp=0;

                    System.out.println("請選擇點贊菜品:");
                    hp=sc.nextInt();
                    if (hp<1||hp>dishes.length){
                        System.out.println("對不起,輸入有誤,請重新輸入!");
                    }else{
                        hot[hp-1]++;
                    }

                    break;
//退出系統(tǒng)------------------------------------------------------------------------------------
                default:
                    System.out.println("6、退出系統(tǒng)");

            }
//switch結(jié)束--------------------------------------------------------------------------------------
            if (chose>0&&chose<6){
                System.out.println("輸入0返回!");
                chose=sc.nextInt();
            }else {
                break;
            }
//-----------------------------------------------------------------------------
        }while (chose==0);
        System.out.println("輸入0返回!");
    }

}

以上是“如何使用Java實現(xiàn)簡單點餐系統(tǒng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(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)容。

AI