软件工程网络15结对编程1——四则运算优化

1.链接

  • 学号:201521123076 博客链接:http://www.cnblogs.com/slickghost/p/8645842.html
  • 学号:201521123078 博客链接:http://www.cnblogs.com/onetruck/p/8641053.html
  • 结对编程码云项目链接:https://gitee.com/534160110/Arithmetic

2.改进现有代码

  • 所选择的博客地址:http://www.cnblogs.com/shizhuangde
  • 源代码:https://coding.net/u/lhl1212/p/work2/git

一、分析初始代码

类图

1108041-20180325152737911-970165912.png

覆盖率统计

1109904-20180325182351521-418469675.png
1109904-20180325182401375-1636939776.png
1109904-20180325182408865-1781716390.png
1109904-20180325182416820-821585217.png

单元测试

1109904-20180325182433601-8832287.png
1109904-20180325182440309-1214806482.png
1109904-20180325182445404-731947879.png

所发现的不足之处

  • 类没有注释,减少易读性
  • 源程序中使用驼峰命名法,但是一些方法的命名有缺陷,如Fraction类中的creatfraction(),应改为createFraction()
  • 不能让用户选择题目的数量
  • 没有统计正确率
  • 只有两个数之间的运算

二、功能改进与扩展

  • 为每个类增加注释,修改不恰当的命名
    1108041-20180325191227070-574446791.png

  • 重构Calculator类,增加calc()方法

          //Class Calculator
           public static String calc(String op,Fraction a,Fraction b){
               switch (op) {
                  case "+":
                      System.out.println("+");
                      return add(a,b);
                  case "-":
                      return sub(a,b);
                  case "×":
                      return mul(a,b);
                  case "÷":
                      return div(a,b);
                  default :
                      return null;
                  }
           }
  • 扩展了三位数之间的运算

     public static String createRandomOp(){
         String operator = null;
         Random random = new Random();
         switch (random.nextInt(4)) {
         case 0:
             operator = "+"; 
             break;
         case 1:
             operator = "-";
             break;
         case 2:
             operator = "×";
             break;
         case 3:
             operator = "÷";
             break;
         }
         return operator;
     }   
    
     public class Createformula {
     public static int testNum = 5; 
     private String[] result = new String[testNum]; 
     private String[] number_1 = new String[testNum]; 
     private String[] number_2 = new String[testNum];
     private String[] number_3 = new String[testNum];
     private String[] operator1 = new String[testNum]; 
     private String[] operator2 = new String[testNum]; 
     private ArrayList<String> scoresList = new ArrayList<String>(); 
     private BufferedWriter writer;
    
     public Createformula() {
    
     }
     public void createTest() {
         Random random = new Random();
         Fraction f1 = new Fraction();
         Fraction f2 = new Fraction();
         Fraction f3 = new Fraction();
         for (int i = 0; i < testNum; i++) {
                f1.creatfraction();
                f2.creatfraction();
                f3.creatfraction();
             number_1[i] = f1.getFraction();
             number_2[i] = f2.getFraction();
             number_3[i] = f3.getFraction();
             operator1[i] = createRandomOp();
             operator2[i] = createRandomOp();
             Fraction temp = new Fraction();  //put the result of f1f2
         if(operator1[i].equals("+")||operator1[i].equals("-") ){
             temp.setFraction(Calculator.calc(operator2[i],f2,f3));
             temp.convertResult();
             result[i] = Calculator.calc(operator1[i],f1,temp);
         }
         else{
             temp.setFraction(Calculator.calc(operator1[i],f1,f2));
             temp.convertResult();
             result[i] = Calculator.calc(operator2[i],temp,f3);
         }
         }
     }  
    
      //Class Fraction
     public  void convertResult(){
         if(fraction != null){
         if(fraction.contains("/")){
             String str[] = fraction.split("/");
             this.numerator = Integer.parseInt(str[0]);
             this.denominator = Integer.parseInt(str[1]);
                 }
         else{
             this.numerator = Integer.parseInt(fraction);
             this.denominator = 1;
         }
     }
         else System.out.println("fraction null");
     }  
  • 增加用户选择题目数量功能

      //Class Background
      public void setFormulaNum() {
          String str; 
          str = JOptionPane.showInputDialog("请输入题目数量"); 
          this.formulaNum = Integer.parseInt(str);
      }  
  • 增加正确率统计功能

      //Class Background
      public void actionPerformed(ActionEvent e) {
              btnExit.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mouseClicked(MouseEvent arg0) {
                      // TODO Auto-generated method stub
                      System.exit(0);
                  }
              });
    
              btnSubmit.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mouseClicked(MouseEvent arg0) {
                      // TODO Auto-generated method stub
                      isEnd=!isEnd; 
                      for (int i = 0; i < formulaNum; i++) {
                          answers[i]=tfdAnswer[i].getText();  
                      }
                      wrong= background.checkAnswer(answers);
                      String s=null;
                      if(wrong.length==0)
                          s=tips.get(5);
                      else{
                          s=tips.get(6)+"\n";
                          String standardAnswer[]=new String[formulaNum];
                          standardAnswer=background.getStandardAnswer();
                          questions = background.getQuestions();
                          for(int i=0;i<wrong.length;i++){
                              s=s+questions[new Integer(wrong[i])-1]+standardAnswer[new Integer(wrong[i])-1];
                              s=s+"\n\n\n";
                              }
                          s = s + tips.get(7)+
                                  String.valueOf(background.getRightAnswer()*100/background.testNum) +"%";
                          }
    
    
    
                      JOptionPane.showMessageDialog(null, s, "错题",JOptionPane.PLAIN_MESSAGE);;
                  }
    
    
              });  
  • 运行结果截图:
    1108041-20180325200005469-2034796864.png

1108041-20180325191901380-1490461885.png

1108041-20180325195944261-1631308362.png

1108041-20180325200215624-1359953856.png

3.两人合作

一、编码规范

  • 1.使用驼峰命名法
  • 2.缩进:tab
  • 3.类的开头注释

二、结对照片

1108041-20180325202251078-1785208388.png

个人开发流程预估耗费时间(min)实际耗费时间(min)
planning3030
estimate1520
development6070
analysis3020
design spec105
design review105
coding standard1510
design3040
coding12090
code review1010
test1020
reporting1015
测试报告105
计算工作量57
提出过程改进计划1015

三、码云提交记录

1108041-20180325201025239-1078400084.png

四、心得体会

结对编程确实能够带来1+1>2的效果,两个人互相讨论后各司其职,其中遇到问题互相帮助。

转载于:https://www.cnblogs.com/onetruck/p/8641053.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值