• 结对编程1


    学号: 201421123084 潘益靖

           201421123085 童毅南

    Coding.net:https://coding.net/user

    a. 需求分析:

      ①丶计时功能,添加计时功能能够让用户更好的了解自己的计算能力的提高表现。

      ②丶语言版本的切换,切换语言版本可以方便用户选择适合自己的版本。

      ③丶记录用户的对总数,可以让用户直观的了解一路走来的历程。

    b. 程序设计:

      ①丶计时功能,我们通过在接收到用户输入的题目数量后用systeem.currentTimeMillis来获取系统的当前时间(是以毫秒为单位的),并且在用户做完题目后软件算出结果

        后提交答案时再用一次System.currentTimeMills将两次获取的当前时间相减后的时间换算成小时,分钟,秒输出到jsp页面上

      ②丶语言版本的切换,我们通过定义一个语言版本的数组将要用到的三种语言的输出语句放进去,在用户选择了语言版本后,我们在使用相对应的languageVersion【i】来

      输出到jsp页面

      ③丶记录用户的对总数,我们用两个int型的整数来装总对题数和总错题数,再每次用户做完题目后输出。

     

    c.代码展示:

    User类

      1 package com.edu.jmu.component;
      2 
      3 import java.util.ArrayList;
      4 
      5 public class User {
      6     protected int historyRight = 0;
      7     protected int historyFalse = 0;
      8     protected int totalNum = 0;
      9     protected int rightNum = 0;
     10     private String runTime;
     11     private ArrayList<RandomGenerator> problems;
     12     private ArrayList<ResultsAndAssess> raa;
     13     public int version = 0;// 语言版本序号
     14 
     15     public static final String[] languageVersion = { "right!", "false!   **the correct answer is:",
     16             "Finished! The total questions are:", "and the right questions are:", ";The correct rate is:",
     17             "The history is total Right:", ",total False:", "Total run time:", "正确!", "错误!   正确答案是:", "结束!总题数为:",
     18             "而且正确题数为:", "正确率为:", "历史记录是总正确数:", ",总错误数:", "总共用时:", "正確!", "錯誤!   正確答案是:", "結束!總題數為:", "而且正確的題數為:",
     19             ";正確率為:", "歷史記錄是總正確數:", ",總錯誤數是:", "總共用時:" };// 语言库
     20 
     21     public User() {
     22         // TODO Auto-generated constructor stub
     23         problems = new ArrayList<RandomGenerator>();
     24         raa = new ArrayList<ResultsAndAssess>();
     25     }
     26 
     27     public void setHistoryRight(int n) {
     28         this.historyRight = rightNum + n;
     29     }
     30 
     31     public void setHistoryFalse(int n) {
     32         this.historyFalse = (totalNum - rightNum) + n;
     33     }
     34 
     35     public String getHistory() {
     36         String history = String.format("%s%d%s%d", languageVersion[8 * version + 5], historyRight,
     37                 languageVersion[8 * version + 6], historyFalse);
     38         return history;
     39     }
     40 
     41     public ArrayList<RandomGenerator> getProblems() {
     42         return problems;
     43     }
     44 
     45     public void setVersion(int version) {
     46         this.version = version;
     47     }
     48 
     49     public boolean userInputNum(String num) {
     50         problems.clear();
     51         RandomGenerator problem;
     52         if (num.matches("[0-9]+")) {
     53             int n = Integer.parseInt(num);
     54             this.totalNum = n;
     55             for (int i = 0; i < n; i++) {
     56                 problem = new RandomGenerator();
     57                 problems.add(i, problem);
     58             }
     59             return true;
     60         }
     61         return false;
     62     }
     63 
     64     public String getCorrectRate() {
     65         String end = String.format("%s %d
     %s %d
     %s %.2f%s
    ", languageVersion[8 * version + 2], this.totalNum,
     66                 languageVersion[5 * version + 3], this.rightNum, languageVersion[8 * version + 4],
     67                 (((double) rightNum) / totalNum) * 100, "%");
     68         rightNum = 0;
     69         return end;
     70     }
     71 
     72     public void userInputResult(String[] userResults) {
     73         raa.clear();
     74         for (int i = 0; i < userResults.length; i++) {
     75             ResultsAndAssess temp = new ResultsAndAssess();
     76             temp.setProblem(this.problems.get(i));
     77             temp.setUserResult(new Fraction(userResults[i].trim()));
     78             if (temp.isAssess()) {
     79                 rightNum++;
     80                 temp.setDescription(languageVersion[8 * version]);
     81             } else {
     82                 temp.setDescription(languageVersion[8 * version + 1]);
     83             }
     84             raa.add(i, temp);
     85         }
     86     }
     87 
     88     public ArrayList<ResultsAndAssess> getRaa() {
     89         return raa;
     90     }
     91 
     92     /**
     93      * @return the runTime
     94      */
     95     public String getRunTime() {
     96         return runTime;
     97     }
     98 
     99     /**
    100      * @param runTime
    101      *            the runTime to set
    102      */
    103     public void setRunTime(long time1, long time2) {
    104 
    105         this.runTime = languageVersion[version * 8 + 7] + ":" + GetTime.getTime(time1, time2);
    106     }
    107 }

     1 package com.edu.jmu.component;
     2 
     3 import java.util.Random;
     4 
     5 public class RandomGenerator {
     6     protected Fraction para1;
     7     protected Fraction para2;
     8     protected Fraction result;
     9     protected int operator;
    10     protected final String[] operators = { "+", "-", "×", "÷" };
    11 
    12     public RandomGenerator() {
    13         para1 = this.getRandomPara();
    14         para2 = this.getRandomPara();
    15         operator = (new Random()).nextInt(4);
    16     }
    17 
    18     public Fraction getRandomPara() {
    19         Random r = new Random();
    20         int m = r.nextInt(20) + 1;
    21         int n = r.nextInt(20) + 1;
    22         if (r.nextBoolean()) {
    23             return new Fraction(m * n, n);
    24         } else {
    25             while (m > n) {
    26                 m = r.nextInt(20) + 1;
    27                 n = r.nextInt(20) + 1;
    28             }
    29             return new Fraction(m, n);
    30         }
    31     }
    32 
    33     public Fraction getPara1() {
    34         return para1;
    35     }
    36 
    37     public void setPara1(Fraction para1) {
    38         this.para1 = para1;
    39     }
    40 
    41     public Fraction getPara2() {
    42         return para2;
    43     }
    44 
    45     public void setPara2(Fraction para2) {
    46         this.para2 = para2;
    47     }
    48 
    49     public Fraction calResult() {
    50         switch (operator) {
    51         case 0:
    52             result = Calculator.addFraction(para1, para2);
    53             break;
    54         case 1:
    55             checkSubValue();
    56             result = Calculator.subFraction(para1, para2);
    57             break;
    58         case 2:
    59             result = Calculator.mulFraction(para1, para2);
    60             break;
    61         case 3:
    62             result = Calculator.devideFraction(para1, para2);
    63             break;
    64         }
    65         return result;
    66     }
    67 
    68     public void checkSubValue() {
    69         int lcm = (para1.getDivisor() * para2.getDivisor())
    70                 / Fraction.commonDivisor(para1.getDivisor(), para2.getDivisor());
    71         int numerator1 = (lcm / para1.getDivisor()) * para1.getNumerator();
    72         int numerator2 = (lcm / para2.getDivisor()) * para2.getNumerator();
    73         if (numerator1 < numerator2) {
    74             Fraction temp = new Fraction(para1.getNumerator(), para1.getDivisor());
    75             para1.setNumerator(para2.getNumerator());
    76             para1.setDivisor(para2.getDivisor());
    77             para2.setNumerator(temp.getNumerator());
    78             para2.setDivisor(temp.getDivisor());
    79         }
    80     }
    81 
    82     @Override
    83     public String toString() {
    84         if (operator == 1) {
    85             checkSubValue();
    86         }
    87         return para1 + " " + operators[operator] + " " + para2 + " = ";
    88     }
    89 }

    两个jsp页面

     1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"
     2     isELIgnored="false"%>
     3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
     4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     5 <html>
     6 <head>
     7 <title>Calculator Setting</title>
     8 <meta charset="utf-8">
     9 <meta http-equiv="pragma" content="no-cache">
    10 <meta http-equiv="cache-control" content="no-cache">
    11 <meta http-equiv="expires" content="0">
    12 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    13 <meta http-equiv="description" content="This is my page">
    14 </head>
    15 
    16 <style>
    17 #container{
    18     
    19     
    20     margin:0 auto;
    21     background-image: url("Image/backGround.jpg") ;
    22     background-position:300px 60px;
    23     background-repeat:no-repeat; 
    24 }
    25 h1 {
    26     text-align: center;
    27     padding: 20px;
    28     font-family: Georgia;
    29 }
    30 
    31 div {
    32     text-align: center;
    33     padding: 20px;
    34     font-size: 20px;
    35     font-family: Georgia;
    36     
    37 }
    38 
    39 button {
    40     font-size: 18px;
    41     font-family: Georgia;
    42 }
    43 
    44 input {
    45     font-family: Georgia;
    46     font-size: 18px;
    47 }
    48 
    49 </style>
    50 
    51 <script type="text/javascript">
    52     function jump(){
    53         alert("清空记录成功!");
    54         location.href="<c:url value="/CalMgr"/>?act=clear";
    55     }
    56     function setVersion(i){
    57         location.href="<c:url value="/CalMgr"/>?act=setversion&&version="+i;
    58     }
    59 </script>
    60 <body>
    61 <div id="container">
    62     <h1>Calculator Generator Web Version</h1>
    63     <div>
    64         请选择语言版本:
    65         <button onclick="setVersion(0)">英文</button>
    66         <button onclick="setVersion(1)">简体中文</button>
    67         <button onclick="setVersion(2)">繁体中文</button>
    68     </div>
    69     <form action="<c:url value="/CalMgr"/>" method="get">
    70         <input type="hidden" value="listGenerate" name="act">
    71         <div>
    72             请输入生成题数:<input type="number" name="calnum" min="1" max="100">
    73         </div>
    74         <div>
    75             <input type="submit" value="生成"> <input type="button"
    76                 value="清空记录" onclick="jump()">
    77         </div>
    78     </form>
    79 </div>
    80 </body>
    81 </html>

    list_problems.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"
        isELIgnored="false"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>题目</title>
    <meta charset="utf-8">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    
    <style type="text/css">
    #container{
        margin:0 auto;
        background-image: url("Image/background2.jpg") ;
        
        width: auto;
        height: auto;
        
    }
    
    table {
        margin:0 auto;
        text-align: right;
        font-size: 20px;
        font-family: Georgia;
        
    }
    #submit{
        width: 50px;
        margin:10 auto 10 auto;
    }
    input {
        font-family: Georgia;
        font-size: 20px;
    }
    
    td {
        padding-bottom: 20px;
        padding-left: 20px;
    }
    
    </style>
    
    </head>
    
    <body>
    <div id="container">
        <form action="<c:url value="/CalMgr"/>" method="get">
            <input type="hidden" name="act" value="listResults">
            <table>
                <tr>
                    <th>序号</th>
                </tr>
                <c:forEach var="pro" items="${problemsList}" varStatus="idx">
                    <tr>
                        <td>${idx.index+1 }、</td>
                        <td>${pro }</td>
                        <td><input type="text" name="userResults" size=9
                            placeholder="?"></td>
                    </tr>
                </c:forEach>
            </table>
            <div id="submit">
                <input type="submit" value="提交">
            </div>
        </form>
    </div>
    </body>
    </html>

    d.程序运行:

            程序进入页面

             

    用户输入答案时界面

           

    英文版本下的输出结果 

    简体中文下的输出结果

    繁体中文下的输出结果

    e.PSP

    PSP2.1 Personal Software Process Stages Time (%) Senior Student Time (%)
    Planning 计划 45min 50min
    · Estimate 估计这个任务需要多少时间 15min 35min
    Development 开发 ? ?
    · Analysis 需求分析 (包括学习新技术) 1h 1.5h
    · Design Spec 生成设计文档 ? ?
    · Design Review 设计复审 13min 20min
    · Coding Standard 代码规范 ? ?
    · Design 具体设计 75min 100min
    · Coding 具体编码 8h 10h
    · Code Review 代码复审 1h 1.5h
    · Test 测试(自我测试,修改代码,提交修改) 3h 2.8h
    Reporting 报告 40min 45min
    · 测试报告 5min 5min
    · 计算工作量 10min 12min
    · 并提出过程改进计划 5min 5min

     

    f.团队照片:

    g. 小结感受:

      结对编程真的能够带来1+1>2的效果吗?答案是肯定的,我觉得对于两个人都是大于双倍的收获。

      通过这次的结对编程,了解到了大神的编程思想,因为用的不是我的代码,看了人家的代码,发现人家才是面向对象的编程,之前自己的函数传参都是以什么Int、String、数

      组啊之类的,而面向对象应该以对象为参数来相互调用。这一点是这次最大的收获

      由于我们用的是javaweb来编写前端的界面,对web的理解又进步了那么一点点。

      感受:结对编程我需要学习队友的好的编程习惯和编程的类的设计的先后关系对我来说还是很有帮助的,这种编程方式我觉得还是挺好的。

  • 相关阅读:
    Linux 高性能server编程——高级I/O函数
    中国儿童移动游戏市场解读 潜力巨大有待开发
    HDU 2152 Fruit (母函数)
    Currying vs Partial Application
    我的最爱Lambda演算——开篇
    函数式编程-数据结构+算法
    高阶函数 、高阶类型
    高阶函数-哈哈
    备份-泛函编程(23)-泛函数据类型-Monad
    高阶函数
  • 原文地址:https://www.cnblogs.com/smile12231/p/6549582.html
Copyright © 2020-2023  润新知