91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

如何使用Java實現簡單點餐系統

發布時間:2022-01-26 09:00:11 來源:億速云 閱讀:148 作者:小新 欄目:開發技術

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

程序控制分析:

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

要求:

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

簽收訂單:改變訂單狀態,已預定可以簽收,如果已經完成則不能再次簽收。

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

我要點贊:對相應的餐品點贊,并展示。

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("歡迎關嶺紅浪漫餐廳");
        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、退出系統");
            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("份數");
                        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]="已預定";                      //orders第二存儲 訂單信息
                            break;
                        }
                    }

                    break;
//查看餐袋------------------------------------------------------------------------------
                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序號\t訂餐人  餐品信息 時間 地址 總金額    訂單狀態");
                    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訂餐人  餐品信息 時間 地址 總金額    訂單狀態");
                    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 ("已預定".equals(orders[num-1][1])){
                            orders[num-1][1]="已完成";
                            System.out.println("訂單已完成");
                            break;
                        }else{
                            System.out.println("訂單已簽收,不能重復簽收");
                            break;
                        }

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

                    break;
//刪除訂單------------------------------------------------------------------------
                case 4:
                    System.out.println("***刪除訂單***");
                    int n=0;   //輸入數字
                    int e=0;  // 訂單的最大數量
                    System.out.println("序號\t訂餐人 \t餐品信息 \t送餐時間 \t地址 \t總金額 \t狀態");
                    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++) {        //確定訂單的最大數量
                            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;
//退出系統------------------------------------------------------------------------------------
                default:
                    System.out.println("6、退出系統");

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

}

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

芦山县| 库车县| 吴旗县| 宁国市| 平和县| 油尖旺区| 长白| 郸城县| 新营市| 北海市| 平遥县| 独山县| 唐山市| 吉首市| 宜兰县| 南平市| 梅州市| 噶尔县| 崇礼县| 永州市| 合阳县| 托里县| 闵行区| 芦溪县| 鱼台县| 临漳县| 镶黄旗| 丰台区| 汉中市| 博兴县| 基隆市| 临高县| 卢氏县| 赤城县| 团风县| 崇文区| 南召县| 屯留县| 乐安县| 美姑县| 长白|