學号: 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\n %s %d\n %s %.2f%s\n", 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 | 代碼複審 | ||
· Test | 測試(自我測試,修改代碼,送出修改) | 3h | 2.8h |
Reporting | 報告 | 40min | |
· | 測試報告 | 5min | |
計算工作量 | 10min | 12min | |
并提出過程改進計劃 |
f.團隊照片:
g. 小結感受:
結對程式設計真的能夠帶來1+1>2的效果嗎?答案是肯定的,我覺得對于兩個人都是大于雙倍的收獲。
通過這次的結對程式設計,了解到了大神的程式設計思想,因為用的不是我的代碼,看了人家的代碼,發現人家才是面向對象的程式設計,之前自己的函數傳參都是以什麼Int、String、數
組啊之類的,而面向對象應該以對象為參數來互相調用。這一點是這次最大的收獲
由于我們用的是javaweb來編寫前端的界面,對web的了解又進步了那麼一點點。
感受:結對程式設計我需要學習隊友的好的程式設計習慣和程式設計的類的設計的先後關系對我來說還是很有幫助的,這種程式設計方式我覺得還是挺好的。