1. 程式人生 > >軟工網絡15結對編程練習

軟工網絡15結對編程練習

divisor design 時間 ber simple ror http public 運行

1.改進現有代碼

  • 博客鏈接
    201521123017
    201521123015

  • 碼雲:
    使用圖形界面實現四則運算
    四則運算優化

  • 類圖
    技術分享圖片

  • JUnit單元測試
    技術分享圖片

  • 運行截圖

    • 四則運算優化

    技術分享圖片

    • 使用圖形界面實現四則運算

    技術分享圖片

    技術分享圖片

    技術分享圖片

2.功能改進與擴展

  • 乘方

            if(s.indexOf("^")>-1){
                int i=s.indexOf("^");
    
                if(s.indexOf("^",i+1)==i+1){
                    throw new IllegalArgumentException("Input error! Don‘t like 1++1");//格式錯誤時拋出異常
                    }else{
    
                        power(s);
                        }
                }//用於檢測是否為乘方
        public void power(String s)//乘方
        {
    
            String[] str=s.split("\\^");
    
            int number=Integer.parseInt(str[1]);
    
            if(str[0].indexOf("/")>-1 )//分數
            {
                String[] str1=str[0].split("[/]");
    
                if(Integer.parseInt(str1[1]) != 0 )//分母不為零
                {
                    int a=1;
                    int b=1;
                    for(int i=0;i<number;i++){
                        a=a*Integer.parseInt(str1[0]);
                        b=b*Integer.parseInt(str1[1]);
                    }
                    result=simplefraction(a,b);
    
                }else{
                    throw new IllegalArgumentException("Divisor cannot be zero!");//除數為零時拋出異常
                }
            }
            else{//整數
               if( Integer.parseInt(str[0])<1000&&Integer.parseInt(str[1])<1000&&Integer.parseInt(str[0])>-1000&&Integer.parseInt(str[1])>-1000)
                {          
                   int c=1;
                   for(int i=0;i<number;i++){
                       c=c*Integer.parseInt(str[0]);
                   }
    
                   result = c+""; 
                   }        
    
           else{
               throw new IllegalArgumentException("overrun!");}//數值範圍超出時拋出異常
           } 
    
        }
  • 運行截圖

技術分享圖片

  • 通過“^”來判定是否為乘方運算,若是類似“1++1”,則拋出錯誤,若是公式無錯,則進入運算,分兩種情況:整數和真分數,通過for循環實現乘方運算。與java原有的乘方有所差異,頭文件:#include

3.在兩人合作的過程中, 請看下面的內容

  • 代碼風格規範和代碼設計規範

技術分享圖片

  • 碼雲提交記錄

    • 四則運算優化

    技術分享圖片

    技術分享圖片

    • 使用圖形界面實現四則運算

    技術分享圖片

    技術分享圖片

  • 結對編程照片

技術分享圖片

  • 測評
PSP2.1 個人開發流程 預估耗費時間(分鐘) 實際耗費時間(分鐘)
Planning 計劃 10 15
· Estimate 明確需求和其他相關因素,估計每個階段的時間成本 10 12
Development 開發 60 75
· Analysis 需求分析 (包括學習新技術) 10 20
· Design Spec 生成設計文檔 10 15
· Design Review 設計復審 6 8
· Coding Standard 代碼規範 5 3
· Design 具體設計 8 9
· Coding 具體編碼 40 45
· Code Review 代碼復審 5 4
· Test 測試(自我測試,修改代碼,提交修改) 8 13
Reporting 報告 7 8
. 測試報告 3 2
. 計算工作量 1 1
. 並提出過程改進計劃 3 3

軟工網絡15結對編程練習