為響應政府網路分級制度,本站全部內容為限制級。未滿十八歲的小朋友趕快關掉網頁去玩皮卡丘打排球吧。

[計概]第一次作業

因為不小心上傳錯,所以倒置本次作業只有五分同情分…為了哀悼,特別把它的遺體po上來,讓大家瞻仰一下它的遺容…

--

public class HomeWork{
    public static void main(String args[]){

    /* 主菜類 */
    String manu[] = new String[4];
    manu[0] = ("豬肉絲");
    manu[1] = ("清燉牛肉");
    manu[2] = ("紅燒牛肉");
    manu[3] = ("牛雜");

    int price[] = new int[4];
    price[0] = 50;
    price[1] = 110;
    price[2] = 90;
    price[3] = 90;

    /* 副菜類 */
    String submanu[] = new String[4];
    submanu[0] = ("燙青菜");
    submanu[1] = ("手工水餃");
    submanu[2] = ("白飯");
    submanu[3] = ("冷飲");

    int subprice[] = new int[4];
    subprice[0] = 30;
    subprice[1] = 3;
    subprice[2] = 10;
    subprice[3] = 12;

    /* 記數用 */
    int i = 0;
    int j = 0;
    int k = 0;
    /* 顯示菜單 */
    System.out.println ("歡迎光臨點餐諮詢系統,以下是本系統所有的餐點。\n\n主菜類:");
        while(i <= 3){
            System.out.println (manu[i] + " 價錢:" + price[i]);
            i++;
        }

        if (i == 4){i = 0;}

    System.out.println ("\n副菜類:");

        while(j <= 3){
            System.out.println (submanu[j] + " 價錢:" + subprice[j]);
            j++;
        }

        if (j == 4){j = 0;}

    System.out.print ("\n請輸入您的用餐預算:");
    int budget = ConsoleIn.readLineInt();

    /* 金額輸入確認 */
    System.out.print ("\n您的用餐預算是:" + budget + "元。確認嗎?(Y/N):");
    char op = ConsoleIn.readLineNonwhiteChar();   

    while ((int)op != 89) {
        while ((int)op != 78 && (int)op != 89) {
            System.out.print ("請輸入Y或N(皆為大寫):");
            op = ConsoleIn.readLineNonwhiteChar();
        }

        while ((int)op == 78) {   
            System.out.print ("請重新輸入您的用餐預算:");
            budget = ConsoleIn.readLineInt();
            System.out.print ("\n您的用餐預算是:" + budget + "元。確認嗎?(Y/N)");
            op = ConsoleIn.readLineNonwhiteChar();
        }
    }
    System.out.println ("用餐預算:" + budget + "元,已確認。");

    /* 檢查符合預算的餐點 */

    /* 未到最低標準 */
    if (budget < 50){
    System.out.println ("\n抱歉,沒有符合您預算的主餐。");
    }

    else{
        System.out.println ("\n以下是符合預算的餐點:\n");
        while(i <= 3){
            if( budget >= price[i]){
                System.out.println (manu[i] + " 價錢:" + price[i] + "元");
                System.out.println ("尚有餘額:" + (budget - price[i]) + "元");
                while(j <= 3){
                    if((budget - price[i]) >= subprice[j]){
                        if(k != 0){
                            System.out.print ("或是,");
                        }
                        if(k == 0){
                            System.out.println ("除此之外還夠買以下的副菜:");
                            k++;
                        }
                    System.out.println (submanu[j] + " " + ((budget - price[i]) / subprice[j]) + "份。");
                    }
                j++;
                }
        if (k != 0){k = 0;}
        System.out.println (" ");
        if (j == 4){j = 0;}

        }
        i++;
    }

    if (i == 4){i = 0;}

    }
    }

}

沒有留言:

張貼留言

已經到底了,不要再拉了!