PTA作業4、5、6及期中考試的總結

来源:https://www.cnblogs.com/zw-1/archive/2023/11/19/17842596.html
-Advertisement-
Play Games

寫在前面 今天狀態很不好,我發現學這部分知識的時候,會出現溜號或者註意力無法集中的情況。 我能想到的是,大概率是這部分知識,應該是超出了我現在的水平了,也就是說我存在知識斷層了,整體感覺真的是一知半解。 那有同學會問了,那你能說明白嗎? 我理解的肯定能呀,來往下看! Flask的使用 1、消息閃現的 ...


一、前言

本次博客是針對面向對象程式設計課程佈置的PTA第4、5、6次作業以及期中考試的編程題而寫的總結分析,重點分析了菜單計價系列題目、期中考試的編程題等具有一定難度和特色的問題。

 

二、PTA第四次作業

這次作業有四道題目,其中難度最大且分值最高的題目就是菜單計價程式-3,該題在菜單計價程式-2的基礎上添加了時間折扣,判斷代點菜信息等功能。

設計點菜計價程式,根據輸入的信息,計算並輸出總價格。

輸入內容按先後順序包括兩部分:菜單、訂單,最後以"end"結束。

菜單由一條或多條菜品記錄組成,每條記錄一行

每條菜品記錄包含:菜名、基礎價格 兩個信息。

訂單分:桌號標識、點菜記錄和刪除信息、代點菜信息。每一類信息都可包含一條或多條記錄,每條記錄一行或多行。

桌號標識獨占一行,包含兩個信息:桌號、時間。

桌號以下的所有記錄都是本桌的記錄,直至下一個桌號標識。

點菜記錄包含:序號、菜名、份額、份數。份額可選項包括:1、2、3,分別代表小、中、大份。

不同份額菜價的計算方法:小份菜的價格=菜品的基礎價格。中份菜的價格=菜品的基礎價格1.5。小份菜的價格=菜品的基礎價格2。如果計算出現小數,按四捨五入的規則進行處理。

刪除記錄格式:序號 delete

標識刪除對應序號的那條點菜記錄。

如果序號不對,輸出"delete error"

代點菜信息包含:桌號 序號 菜品名稱 份額 分數

代點菜是當前桌為另外一桌點菜,信息中的桌號是另一桌的桌號,帶點菜的價格計算在當前這一桌。

程式最後按輸入的先後順序依次輸出每一桌的總價(註意:由於有代點菜的功能,總價不一定等於當前桌上的菜的價格之和)。

每桌的總價等於那一桌所有菜的價格之和乘以折扣。如存在小數,按四捨五入規則計算,保留整數。

折扣的計算方法(註:以下時間段均按閉區間計算):

周一至周五營業時間與折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其餘時間不營業。

周末全價,營業時間:9:30-21:30

如果下單時間不在營業範圍內,輸出"table " + t.tableNum + " out of opening hours"

參考以下類的模板進行設計:菜品類:對應菜譜上一道菜的信息。

Dish {

String name;//菜品名稱

int unit_price; //單價

int getPrice(int portion)//計算菜品價格的方法,輸入參數是點菜的份額(輸入數據只能是1/2/3,代表小/中/大份) }

菜譜類:對應菜譜,包含飯店提供的所有菜的信息。

Menu {

Dish\[\] dishs ;//菜品數組,保存所有菜品信息

Dish searthDish(String dishName)//根據菜名在菜譜中查找菜品信息,返回Dish對象。

Dish addDish(String dishName,int unit_price)//添加一道菜品信息

}

點菜記錄類:保存訂單上的一道菜品記錄

Record {

int orderNum;//序號\\

Dish d;//菜品\\

int portion;//份額(1/2/3代表小/中/大份)\\

int getPrice()//計價,計算本條記錄的價格\\

}

訂單類:保存用戶點的所有菜的信息。

Order {

Record\[\] records;//保存訂單上每一道的記錄

int getTotalPrice()//計算訂單的總價

Record addARecord(int orderNum,String dishName,int portion,int num)//添加一條菜品信息到訂單中。

delARecordByOrderNum(int orderNum)//根據序號刪除一條記錄

findRecordByNum(int orderNum)//根據序號查找一條記錄

}

### 輸入格式:

桌號標識格式:table + 序號 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 時間(24小時制格式: HH/MM/SS)

菜品記錄格式:

菜名+英文空格+基礎價格

如果有多條相同的菜名的記錄,菜品的基礎價格以最後一條記錄為準。

點菜記錄格式:序號+英文空格+菜名+英文空格+份額+英文空格+份數註:份額可輸入(1/2/3), 1代表小份,2代表中份,3代表大份。

刪除記錄格式:序號 +英文空格+delete

代點菜信息包含:桌號+英文空格+序號+英文空格+菜品名稱+英文空格+份額+英文空格+分數

最後一條記錄以“end”結束。

### 輸出格式:

按輸入順序輸出每一桌的訂單記錄處理信息,包括:

1、桌號,格式:table+英文空格+桌號+”:”

2、按順序輸出當前這一桌每條訂單記錄的處理信息,

每條點菜記錄輸出:序號+英文空格+菜名+英文空格+價格。其中的價格等於對應記錄的菜品\*份數,序號是之前輸入的訂單記錄的序號。如果訂單中包含不能識別的菜名,則輸出“\*\* does not exist”,\*\*是不能識別的菜名

如果刪除記錄的序號不存在,則輸出“delete error”

最後按輸入順序一次輸出每一桌所有菜品的總價(整數數值)格式:table+英文空格+桌號+“:”+英文空格+當前桌的總價

本次題目不考慮其他錯誤情況,如:桌號、菜單訂單順序顛倒、不符合格式的輸入、序號重覆等,在本系列的後續作業中會做要求。

輸入格式:

桌號標識格式:table + 序號 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 時間(24小時制格式: HH/MM/SS)

菜品記錄格式:

菜名+英文空格+基礎價格

如果有多條相同的菜名的記錄,菜品的基礎價格以最後一條記錄為準。

點菜記錄格式:序號+英文空格+菜名+英文空格+份額+英文空格+份數註:份額可輸入(1/2/3), 1代表小份,2代表中份,3代表大份。

刪除記錄格式:序號 +英文空格+delete

代點菜信息包含:桌號+英文空格+序號+英文空格+菜品名稱+英文空格+份額+英文空格+分數

最後一條記錄以“end”結束。

輸出格式:

按輸入順序輸出每一桌的訂單記錄處理信息,包括:

1、桌號,格式:table+英文空格+桌號+“:”+英文空格

2、按順序輸出當前這一桌每條訂單記錄的處理信息,

每條點菜記錄輸出:序號+英文空格+菜名+英文空格+價格。其中的價格等於對應記錄的菜品\*份數,序號是之前輸入的訂單記錄的序號。如果訂單中包含不能識別的菜名,則輸出“\*\* does not exist”,\*\*是不能識別的菜名

如果刪除記錄的序號不存在,則輸出“delete error”

最後按輸入順序一次輸出每一桌所有菜品的總價(整數數值)格式:table+英文空格+桌號+“:”+英文空格+當前桌的總價

本次題目不考慮其他錯誤情況,如:桌號、菜單訂單順序顛倒、不符合格式的輸入、序號重覆等,在本系列的後續作業中會做要求。

我的代碼如下:

package  num1;
import java.util.Calendar;
import java.util.Scanner;
class Dish {
    String name;//菜品名稱
    int unit_price; //單價
//int num;

    int getPrice(int portion) {
        int peic = 0;
        if (portion == 1) {
            peic = unit_price ;
        } else if (portion == 2) {
            peic = Math.round((float) (unit_price * 1.5)) ;
        } else if (portion == 3) {
            peic = (unit_price * 2) ;
        }
        return peic;//計算菜品價格的方法,輸入參數是點菜的份額(輸入數據只能是1/2/3,代表小/中/大份)
    }
}
class Menu {
    Dish[] dishs = new Dish[10];//菜品數組,保存所有菜品信息
    int count = 0;
    Dish searthDish(String dishName){
        Dish temd = null;
        for(int i=count-1;i>=0;i--){
            if(dishName.equals(dishs[i].name)){
                temd = dishs[i];
                break;
            }
        }
        if(temd==null){
            System.out.println(dishName+" does not exist");
        }
        return temd;
    }//根據菜名在菜譜中查找菜品信息,返回Dish對象。
    Dish addDish(String dishName,int unit_price){
        Dish dh = new Dish();
        dh.name = dishName;
        dh.unit_price = unit_price;
        count++;
        return dh;
    }//添加一道菜品信息
}
class Record {
    int orderNum;//序號\
    //int AntherOrderNum;
    Dish d = new Dish();//菜品\
    int num = 0;
    int portion;//份額(1/2/3代表小/中/大份)\
    //int exist = 1;
    int getPrice(){
        return d.getPrice(portion)*num;
    }//計價,計算本條記錄的價格\
}
class Order {
    Record[] records = new Record[10];//保存訂單上每一道的記錄
    int count = 0;//訂單數量
    //int forcount = 0;//代點菜的數量
/*int getTotalPrice(){
int sum=0;
for(int i=0;i<count;i++){
if(records[i].exist==0)
continue;
sum=sum+records[i].getPrice();
}
return sum;
}//計算訂單的總價*/
    void addARecord(int orderNum,String dishName,int portion,int num){
        records[count] = new Record();
        records[count].d.name = dishName;
        records[count].orderNum = orderNum;
        records[count].portion = portion;
        records[count].num = num;
        count++;
    }//添加一條菜品信息到訂單中。
    /*Record TakeOdfor(int AnotherNUm,int orderNum,String dishName,int portion,int num){
    Record rd2 = new Record();
    rd2.d.name = dishName;
    rd2.orderNum = orderNum;
    rd2.portion = portion;
    rd2.d.num = num;
    rd2.AntherOrderNum = AnotherNUm;
    //forcount++;
    return rd2;
    }*/
    int delARecordByOrderNum(int orderNum){
        if(orderNum>count||orderNum<=0){
            System.out.println("delete error;");
            return 0;
        }else {
            return records[orderNum - 1].getPrice();
        }
    }//根據序號刪除一條記錄
}
class Table {
    int tableNum;
    String tableDtime;
    int year,month,day,week,hh,mm,ss;
    int sum = 0;//一桌價格 ;
    // boolean f = true;
    Order odt = new Order();
    //Order odre = new Order();
    float discnt = -1;
    void Gettottalprice(){
        if(discnt>0){
            sum = Math.round(sum*discnt);
            System.out.println("table " + tableNum + ": " + sum);
        }else {
            System.out.println("table " + tableNum + " out of opening hours");
        }
    }
    void AheadProcess(String tableDtime){
        this.tableDtime = tableDtime;
        processTime();
        discount();
//CheckAtime();
    }


    void processTime(){//處理時間
        String[] temp = tableDtime.split(" ");
        tableNum = Integer.parseInt(temp[1]);
        String[] temp1 = temp[2].split("/");
        String[] temp2 = temp[3].split("/");

        year = Integer.parseInt(temp1[0]);
        month = Integer.parseInt(temp1[1]);
        day = Integer.parseInt(temp1[2]);

        Calendar c = Calendar.getInstance();
        c.set(year, (month-1), day);
        week = c.get(Calendar.DAY_OF_WEEK);
        if(week==1)
            week = 7;
        else
            week--;
        hh = Integer.parseInt(temp2[0]);
        mm = Integer.parseInt(temp2[1]);
        ss = Integer.parseInt(temp2[2]);

    }
    //void CheckAtime(){
// f= !(discnt < 0);
// }
    void discount(){
        if(week>=1&&week<=5)
        {
            if(hh>=17&&hh<20)
                discnt=0.8F;
            else if(hh==20&&mm<30)
                discnt=0.8F;
            else if(hh==20&&mm==30&&ss==0)
                discnt=0.8F;
            else if(hh>=11&&hh<=13||hh==10&&mm>=30)
                discnt=0.6F;
            else if(hh==14&&mm<30)
                discnt=0.6F;
            else if(hh==14&&mm==30&&ss==0)
                discnt=0.6F;
        }
        else
        {
            if(hh>=10&&hh<=20)
                discnt= 1.0F;
            else if(hh==9&&mm>=30)
                discnt= 1.0F;
            else if(hh==21&&mm<30||hh==21&&mm==30&&ss==0)
                discnt= 1.0F;
        }
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Menu mu = new Menu();
        Table[] tablemes = new Table[10];
        int j = 0;//菜單數
        int l = 0;//訂單數
        int k = 0;//代點菜數
        Dish tt;
//int sum = 0;
        int cntTable = 0;//桌號
        int count;
        String[] temp;
        int a1,a2,a3,a4,a5;

        while (true) {
            String st = sc.nextLine();
            temp = st.split(" ");
            if(st.equals("end"))
                break;
            count = temp.length;
            if (count == 2) {//一個空格
//String[] temp1 = st.split(" ");
                if (temp[1].equals("delete")) {//第二個為delete
                    a1 = Integer.parseInt(temp[0]);
                    int c = tablemes[cntTable].odt.delARecordByOrderNum(a1);
                    tablemes[cntTable].sum-=c;
                } else {//菜單添加
                    a2 = Integer.parseInt(temp[1]);
                    mu.dishs[j] = mu.addDish(temp[0], a2);
                    j++;
                }
//continue;
            }
            else if (count == 4) {//三個空格
//String[] temp2 = st.split(" ");
                if (temp[0].equals("table")) {//桌號
                    cntTable++;//跳過0;
                    l = 0;
                    tablemes[cntTable] = new Table();
//tablemes[cntTable].tableDtime = st;
                    tablemes[cntTable].AheadProcess(st);

                    System.out.println("table " + cntTable + ": ");
                } else {//增加訂單的情況;
                    a3 =Integer.parseInt(temp[0]);
                    a4 = Integer.parseInt(temp[2]);
                    a5=Integer.parseInt(temp[3]);
                    tablemes[cntTable].odt.addARecord(a3, temp[1],a4 , a5);
                    tt = mu.searthDish(temp[1]);
                    if (tt != null) {
                        tablemes[cntTable].odt.records[l].d = tt;
                        int a = tablemes[cntTable].odt.records[l].getPrice();
                        System.out.println(tablemes[cntTable].odt.records[l].orderNum + " " + tt.name + " " +a );
                        tablemes[cntTable].sum +=a;
                    }
                    l++;
                }
//continue;
            }
            else if (count == 5) {//代點菜
//String[] temp3 = st.split(" ");
                a1 = Integer.parseInt(temp[1]);
                a2 = Integer.parseInt(temp[3]);
                a3 = Integer.parseInt(temp[4]);
                tablemes[cntTable].odt.addARecord( a1, temp[2], a2, a3);
                tt = mu.searthDish(temp[2]);
                if (tt != null) {
                    tablemes[cntTable].odt.records[l].d.unit_price = tt.unit_price;
                    int b = tablemes[cntTable].odt.records[l].getPrice();
                    System.out.println(temp[1] + " table " + tablemes[cntTable].tableNum + " pay for table " + temp[0] + " " + b);
                    tablemes[cntTable].sum += b;
                }
                l++;
            }
//st = sc.nextLine();
        }
        for (int i = 1; i < cntTable + 1; i++) {
            tablemes[i].Gettottalprice();
        }
    }
}

 

  • Dish 類表示菜品,包含菜品名稱和單價,並提供計算菜品價格的方法。
  • Menu 類用於管理菜單,包含菜品數組和菜品數量,提供查找菜品和添加菜品的方法。
  • Record 類表示訂單中的記錄,包含序號、菜品信息、數量和份額,並提供計算記錄價格的方法。
  • Order 類用於管理訂單,包含記錄數組和訂單數量,提供添加記錄和刪除記錄的方法。
  • Table 類表示餐桌,包含桌號、時間信息、總價格和訂單對象,提供計算總價格和處理時間的方法。
  • Main 類是程式的入口點,通過命令行輸入來模擬添加菜品、點菜、刪除訂單等操作。

對該代碼進行類圖分析和複雜度分析如下,結果如下:

sourcemonitor代碼分析結果如下:

 

這次題目對於對java語言及面向對象思想不太熟悉的我來說頗具挑戰,在一個星期的時間內,我不斷調試和優化,還是沒能通過全部測試點。

三、PTA第五次作業

本次作業只有一道題目即菜單計價程式-4,通過對菜單計價程式-3的優化和檢錯,主要針對錯誤輸入的檢測和拋出,來顯示相應的信息。

本次課題比菜單計價系列-3增加的異常情況:

1、菜譜信息與訂單信息混合,應忽略夾在訂單信息中的菜譜信息。輸出:"invalid dish"

2、桌號所帶時間格式合法(格式見輸入格式部分說明,其中年必須是4位數字,月、日、時、分、秒可以是1位或2位數),數據非法,比如:2023/15/16 ,輸出桌號+" date error"

3、同一桌菜名、份額相同的點菜記錄要合併成一條進行計算,否則可能會出現四捨五入的誤差。

4、重覆刪除,重覆的刪除記錄輸出"deduplication :"+序號。

5、代點菜時,桌號不存在,輸出"Table number :"+被點菜桌號+" does not exist";本次作業不考慮兩桌記錄時間不匹配的情況。

6、菜譜信息中出現重覆的菜品名,以最後一條記錄為準。

7、如果有重覆的桌號信息,如果兩條信息的時間不在同一時間段,(時段的認定:周一到周五的中午或晚上是同一時段,或者周末時間間隔1小時(不含一小時整,精確到秒)以內算統一時段),此時輸出結果按不同的記錄分別計價。

8、重覆的桌號信息如果兩條信息的時間在同一時間段,此時輸出結果時合併點菜記錄統一計價。前提:兩個的桌號信息的時間都在有效時間段以內。計算每一桌總價要先合併符合本條件的飯桌的點菜記錄,統一計價輸出。

9、份額超出範圍(1、2、3)輸出:序號+" portion out of range "+份額,份額不能超過1位,否則為非法格式,參照第13條輸出。

10、份數超出範圍,每桌不超過15份,超出範圍輸出:序號+" num out of range "+份數。份數必須為數值,最高位不能為0,否則按非法格式參照第16條輸出。

11、桌號超出範圍[1,55]。輸出:桌號 +" table num out of range",桌號必須為1位或多位數值,最高位不能為0,否則按非法格式參照第16條輸出。

12、菜譜信息中菜價超出範圍(區間(0,300)),輸出:菜品名+" price out of range "+價格,菜價必須為數值,最高位不能為0,否則按非法格式參照第16條輸出。

13、時間輸入有效但超出範圍[2022.1.1-2023.12.31],輸出:"not a valid time period"

14、一條點菜記錄中若格式正確,但數據出現問題,如:菜名不存在、份額超出範圍、份數超出範圍,按記錄中從左到右的次序優先順序由高到低,輸出時只提示優先順序最高的那個錯誤。

15、每桌的點菜記錄的序號必須按從小到大的順序排列(可以不連續,也可以不從1開始),未按序排列序號的輸出:"record serial number sequence error"。當前記錄忽略。(代點菜信息的序號除外)

16、所有記錄其它非法格式輸入,統一輸出"wrong format"

17、如果記錄以“table”開頭,對應記錄的格式或者數據不符合桌號的要求,那一桌下麵定義的所有信息無論正確或錯誤均忽略,不做處理。如果記錄不是以“table”開頭,比如“tab le 55 2023/3/2 12/00/00”,該條記錄認為是錯誤記錄,後面所有的信息併入上一桌一起計算。

本次作業比菜單計價系列-3增加的功能:

菜單輸入時增加特色菜,特色菜的輸入格式:菜品名+英文空格+基礎價格+"T"

例如:麻婆豆腐 9 T

菜價的計算方法:

周一至周五 7折, 周末全價。

註意:不同的四捨五入順序可能會造成誤差,請按以下步驟累計一桌菜的菜價:

計算每條記錄的菜價:將每份菜的單價按份額進行四捨五入運算後,乘以份數計算多份的價格,然後乘以折扣,再進行四捨五入,得到本條記錄的最終支付價格。

最後將所有記錄的菜價累加得到整桌菜的價格。

 

我的代碼如下:

class Worn
{
    void worninput(String[]a,int num,int[]b)
    {
        for(int i=0;i<num;i++)
        {
            String[] arr=a[i].split(" ");
            boolean flag=false;
            //麻婆豆腐 12
            if(arr.length>5)
            {
                b[i]=1;
            }
            if(a[i].matches("^[\u4e00-\u9fa5]{1,} ([1-9][0-9]{0,2})$")==true)//普通菜存入
            {
                flag=true;
            }
            //油淋生菜 9 T
            else if(a[i].matches("^[\u4e00-\u9fa5]{1,4} ([1-9][0-9]{0,2}) [T]$")==true)//特色菜存入
            {
                flag=true;
            }
            //table 31 2023/2/1 14/20/00
            else if(arr[0].equals("table")==true)//
            {
                int blank=0;
                for(int bk=0;bk<a[i].length();bk++)
                {
                    if(a[i].charAt(bk)==' ')
                    {
                        blank++;
                    }
                }
                if(arr[1].matches("^([1-9][0-9]{0,})$")&&blank==3)
                    flag=true;
                //int blank=0;

            }
            //1 麻婆豆腐 1 16
            else if(a[i].matches("^[1-9][0-9]{0,2} [\u4e00-\u9fa5]{1,} [1-9] ([1-9][0-9]{0,1})$")==true)
            {
                flag=true;
            }
            //1 1 麻婆豆腐 1 16
            else if(a[i].matches("^([1-9][0-9]{0,1}) [1-9][0-9]{0,2} [\u4e00-\u9fa5]{1,} [1-9] ([1-9][0-9]{0,1})$")==true)
            {
                flag=true;
            }
            //2 delete
            else if(a[i].matches("^([1-9][0-9]{0,1}) delete$")==true)
            {
                flag=true;
            }
            else if(a[i].matches("^end$")==true)
            {
                flag=true;
            }
            if(flag==false)
            {
                b[i]=1;
            }
        }
    }
}
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String[] a=new String[50];
            int[]b=new int[50];
            Library li = new Library();
            Menu c=new Menu();
            table[] t=new table[50];
            Dish g=new Dish();
            int i=0;//桌號
            int j=0;//菜數
            int p=0;//當前處理桌號
            int lastdish=0;
            int dc1=0,dc2=0,dc3=0,dd1=0,dd2=0,dd3=0,dd4=0;
            int inputnum=0,h;
            a[0] = in.nextLine();
            b[0] = 0;
            while (!a[inputnum].equals("end")) {
                inputnum++;
                a[inputnum] = in.nextLine();
                b[inputnum] = 0;
            }
            Worn w=new Worn();
            w.worninput(a,inputnum,b);
            for(h=0;h<inputnum;h++) {
                if (a[h].isEmpty()) {
                    System.out.println("wrong format");
                } else {
                    boolean flagerror = false;
                    //分割字元
                    String[] arr = a[h].split(" ");
                    if (arr.length == 4 || arr[0].charAt(0) == 't') {
                        if (arr[0].equals("table"))//加桌
                        {
                            flagerror = true;
                            lastdish = 0;
                            table x = new table();
                            x.input(a[h], b[h]);
                            if (i != 0)
                                p = t[i - 1].searchtime(t, x, i);
                            if (p == i)//加新桌
                            {
                                t[i] = new table();
                                t[p] = x;
                                i++;
                                lastdish = 0;//初始化
                                if (t[p].flag)
                                    System.out.println("table " + t[p].tablenum + ": ");
                            } else {
                                if (t[p].flag)
                                    System.out.println("table " + t[p].tablenum + ": ");
                                lastdish = 0;
                            }
                        } else if (arr[0].matches("^[1-9][0-9]{0,1}$"))//自己點菜
                        {
                            if (b[h] == 1) {
                                flagerror = true;
                                if (i != 0 && t[p].flag) {
                                    System.out.println("wrong format");
                                }
                                continue;
                            }
                            dc1 = Integer.parseInt(arr[0]);
                            dc2 = Integer.parseInt(arr[2]);
                            dc3 = Integer.parseInt(arr[3]);
                            if (i != 0 && t[p].flag) {

                                if (i != 0) {
                                    if (dc1 <= lastdish) {
                                        System.out.println("record serial number sequence error");
                                    } else {
                                        t[p].selforder.addARecord(0, dc1, arr[1], dc2, dc3, true);
                                        g = c.searthDish(arr[1]);
                                        if (g != null && t[p].flag) {
                                            if (dc2 > 3 && dc2 < 10 || dc2 <= 0 && dc2 > -10)//情況9
                                            {
                                                //序號+" portion out of range "+份額
                                                System.out.println(dc1 + " portion out of range " + dc2);
                                            } else if (dc3 > 15) {
                                                System.out.println(dc1 + " num out of range " + dc3);
                                            } else {
                                                t[p].selforder.records[t[p].k].d = g;
                                                //System.out.println(t[p].selforder.records[]);
                                                int x = t[p].selforder.records[t[p].k].getPrice();
                                                //2 油淋生菜 27
                                                lastdish = dc1;
                                                System.out.println(dc1 + " " + arr[1] + " " + x);
                                            }
                                        }
                                        t[p].k++;

                                    }
                                }

                            }
                        } else {
                            System.out.println("wrong format");
                            flagerror = true;
                        }
                    } else if (arr.length == 5) {
                        if (b[h] == 1) {
                            flagerror = true;
                            if (i != 0 && t[p].flag) {
                                System.out.println("wrong format");
                            }
                            continue;
                        }
                        dd1 = Integer.parseInt(arr[0]);
                        dd2 = Integer.parseInt(arr[1]);
                        dd3 = Integer.parseInt(arr[3]);
                        dd4 = Integer.parseInt(arr[4]);
                        if (t[p].searthtable(t, dd1, p) == true) {
                            t[p].selforder.addARecord(dd2, dd1, arr[2], dd3, dd4, false);
                            g = c.searthDish(arr[2]);
                            if (g != null) {
                                t[p].selforder.records[t[p].k].d = g;
                                int x = t[p].selforder.records[t[p].k].getPrice();
                                System.out.println(dd2 + " table " + t[p].tablenum + " pay for table " + dd1 + " " + x);
                            }
                            //k++;
                            t[p].k++;
                        }
                    } else if (arr.length == 2) {
                        if (arr[1].equals("delete")) {

                            if (i != 0) {
                                if (b[h] == 1) {
                                    flagerror = true;
                                    if (i != 0) {
                                        System.out.println("wrong format");
                                    }
                                    continue;
                                }
                                if (t[p].flag)
                                    t[p].selforder.delARecordByOrderNum(Integer.parseInt(arr[0]), t[p]);
                            }
                        } else//加菜
                        {
                            if (b[h] == 1) {
                                flagerror = true;
                                System.out.println("wrong format");
                                continue;
                            }
                            if (i != 0 && t[p].flag)//情況1
                            {
                                System.out.println("invalid dish");
                            } else {
                                if (Integer.parseInt(arr[1]) > 0 && Integer.parseInt(arr[1]) < 300) {
                                    c.addDish(arr[0], Integer.parseInt(arr[1]), false);
                                    j++;
                                } else {
                                    System.out.println(arr[0] + " price out of range " + arr[1]);
                                }
                            }
                        }
                    } else if (arr.length == 3) {
                        if (b[h] == 1) {
                            flagerror = true;
                            System.out.println("wrong format");
                            continue;
                        }
                        if (i != 0 && t[p].flag) {
                            System.out.println("invalid dish");
                        } else {
                            if (arr[2].equals("T")) {
                                if (Integer.parseInt(arr[1]) > 0 && Integer.parseInt(arr[1]) < 300) {
                                    c.addDish(arr[0], Integer.parseInt(arr[1]), true);
                                    j++;
              

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 前言 這是第二次博客作業,總結了近三次PTA大作業的完成情況,這三次的大作業難度逐漸增大,完全理不清邏輯,真的越想越混亂,代碼寫的也是很亂,沒有一個整體的框架結構,讀起來很困難,沒有學到java程式編寫的真諦,總之對於我,一個邏輯很差很差的人來說,越來越複雜的題目,寫起來真的痛苦,到後面的題目,基本 ...
  • 按規則解析並替換字元串中的變數及函數 需求 1、按照一定規則解析字元串中的函數、變數表達式,並替換這些表達式。這些函數表達式可能包含其它函數表達式,即支持函數嵌套 2、函數表達式格式:${ __函數名稱() }、${__函數名稱( 函數參數 )} 3、變數表達式格式:${ varName } 註意: ...
  • python 版本:3.6 win32 版本(因為一些特殊原因必須使用3.6) pymssql 版本:2.2.0 連接資料庫: import pymssql** def InitMssql(self): try: host = self.IniConfig.get('default','dbhost ...
  • 學習完基礎的圖像演算法,開始接觸OpenCV學習: 灰度圖中,一個像素點上的灰度級需要一個位元組(byte,2^8,8 bit)進行存儲,此時的灰度圖是二維的。而當我們需要轉換為彩色圖時,即三維,便會產生顏色通道(Channel),這個時候,一個像素點上的灰度級便會需要三個位元組來進行存儲。 可以藉助笛卡 ...
  • 本文只發佈於利用OpenCV實現尺度不變性與角度不變性的特征找圖演算法和知乎 一般來說,利用OpenCV實現找圖功能,用的比較多的是模板匹配(matchTemplate)。筆者比較喜歡裡面的NCC演算法。但是模板有個很明顯的短板,面對尺度改變,角度改變的目標就無能為力了。因此本文旨在做到模板匹配做不到的 ...
  • 目錄: Redis是什麼? Redis優缺點? Redis為什麼這麼快? 講講Redis的線程模型? Redis應用場景有哪些? Memcached和Redis的區別? 為什麼要用 Redis 而不用 map/guava 做緩存? Redis 數據類型有哪些? SortedSet和List異同點? ...
  • 14.1、概述 在實際工作中,一般使用配置類和註解代替web.xml和SpringMVC配置文件的功能; 在 Servlet3.0 環境中,容器會在類路徑中查找實現了 javax.servlet.ServletContainerInitializer 介面的類, 如果找到了的話,就會用它來配置 Se ...
  • int i=1; i=i++; int j=i++; int k=i + ++i * i++; System.out.println("i="+i); System.out.println("j="+j); System.out.println("k="+k); ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...