作業要求來自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2232
GitHub遠端倉庫的位址:https://github.com/RichardSkr/Simple-arithmetic-device
1.開發環境
IDE :IntelliJ IDEA 2018.2.5 x64。
JDK:JDK_U801.
系統:Ubuntu x64.
程式設計語言:Java語言
2.需求分析
- 基本要求:
1)生成題目,單個題目最多不能超過4個運算符,操作數小于100。
2)使用者可以輸入答案
3)若使用者輸入答案正确,則提示正确;若答案錯誤,則提示錯誤,并要提示正确答案是多少。
- 擴充要求(選擇方向):
1)程式可以出帶括号的正整數四則運算,支援分數,除法保留兩位小數,如:(1/3+1)*2 = 2.67,特别注意:這裡是2.67而非2.66,或保持分數形式:8/3;
2)可以出表達式裡含有負整數(負整數最小不小于-100)的題目,且負數需要帶括号,使用者輸入的結果不用帶括号。如: 2*(-4) = -8;
3)使用者答題結束以後,程式可以顯示使用者答題所用的時間;
4)使用者可以選擇出題的個數(最多不能超過5個題目),答題結束可以顯示使用者答錯的題目個數和答對的題目個數;
5)程式可以出單個整數階乘的題目:如:4!=24;
6)程式可以設定皮膚功能,可以改變界面的顔色即可。
3.詳細設計
1)程式可以出帶括号的正整數四則運算,支援分數。
1 int open_parenthesis = rand.nextInt(num.size() - 1); //左括号下标
2 int closed_parenthesis = rand.nextInt(num.size() - open_parenthesis - 1) + 2 + open_parenthesis; //右括号下标
3 this.operator.add(open_parenthesis, "(");
4 this.operator.add(closed_parenthesis, ")");
設計思路:在運算符集合範圍内随機生成左括号下标,在左括号和運算符集合末尾範圍内随機生成右括号下标,然後在運算符集合中,添加括号到對應的位置。
ExerciseBean類中:
1 this.num.add(10 - rand.nextInt(20));
ExerciseUtils類中添加:
1 if (exerciseList.get(index).num.get(j) < 0) {
2 exercise +="(" + exerciseList.get(index).num.get(j) + ")";
3 }
設計思路:在随機生成的整型數值中可以有負數,輸出題目時判斷是否小于0,若小于0則輸出帶括号的負數。
1 Timer timer = new Timer();//計時器
2 timer.schedule(new TimerTask() {
3 public void run() {
4 time++;
5 }
6 }, 0,1000);
設計思路:用計時器獲得使用者答題持續時間。
界面類中:
1 int exerciseCount = 0;//定義出題數變量
2 /**
3 * 設定出題數
4 */
5 private void setExerciseCount(int exerciseCount){
6 this.exerciseCount = exerciseCount;
7 }
ExerciseUtils類中:
1 /**
2 * 擷取題目集合
3 */
4 public static List<ExerciseBean> getExerciseList(int exerciseCount) {
5 List<ExerciseBean> exerciseList = new ArrayList<ExerciseBean>();
6
7 for (int i = 0; i < exerciseCount; i++) {
8 Random rand = new Random();
9 if (rand.nextInt(3) == 0){
10 exerciseList.add(new ExerciseFactorialBean());
11 }else {
12 exerciseList.add(new ExerciseBean());
13 }
14 }
15 return exerciseList;
16 }
設計思路:定義出題數變量,用該變量限定出題量。
定義ExerciseFactorialBean類:
1 package bean;
2
3 import java.util.ArrayList;
4 import java.util.Random;
5
6 public class ExerciseFactorialBean extends ExerciseBean {
7 private int maxFactorial;
8 public ExerciseFactorialBean(){
9 setMaxFactorial(6);
10 createExercise();
11 }
12 private void createExercise() {
13 Random rand = new Random();
14 this.num = new ArrayList<>();
15 this.operator = new ArrayList<>();
16 this.num.add(rand.nextInt(maxFactorial)+1);
17 this.operator.add("!=");
18 }
19
20 /**
21 * 設定階乘最大範圍
22 */
23 private void setMaxFactorial(int maxFactorial){
24 this.maxFactorial = maxFactorial;
25 }
26 @Override
27 public String getAnswer() {
28 int factorial = num.get(0);
29 int answer = 1;
30 for (int i = 0; i < factorial; i++){
31 answer *= (i+1);
32 }
33 return answer + "";
34 }
35 }
修改ExerciseUtils類:
1 Random rand = new Random();
2 if (rand.nextInt(3) == 0){
3 exerciseList.add(new ExerciseFactorialBean());
4 }else {
5 exerciseList.add(new ExerciseBean());
6 }
設計思路:定義一個ExerciseBean的子類ExerciseFactorialBean,重寫createExercise()和getAnswer()方法,在工具類中的習題集合中添加階乘類。
1 VBoxInstance.colorBtn.setOnMouseClicked(event -> {
2 changeColor();
3 mainVBox.setBackground(new Background(new BackgroundFill(color,null,null)));
4 VBoxInstance.colorBtn.setStyle(MainWork2.colorStyle);
5 });
設計思路:在點選顔色按鈕時,改變主面闆和按鈕的背景色。
4.調試結果
限定出題數

判斷答案是否正确
擷取總分數
改變顔色
5.結對項目過程
姓名:陳俊朗
學号:201606120066
結對成員部落格位址:http://www.cnblogs.com/tuyt124/
分工:
1)成員1:随機生成括号算法、生成階乘題目算法、擷取答案算法
2)成員2:圖形化界面設計、生成計時器、更改背景顔色功能
結對項目學習照片:
6.總結
結對程式設計效率會比個人程式設計更高,成員之間可以互相監督、互相學習,解決問題的想法會更多更有效。互相督促可以使我們都能集中精力,更加認真的工作,我們對業務的了解深度相差無幾,設計在我們共同讨論中産生,這樣我們在進行Code Review的時候比起傳統的方式就會更有效。比如我們其中一個人,按照我們共同完成的活動圖去程式設計,完成一小段邏輯後,另外一個人會馬上給出意見,說出代碼存在的潛在問題,這個潛在的問題,很可能是因為我們當時對業務了解存在偏差造成的。很可能這個時候我們要對設計進行改動以适應業務。如果是一個人在程式設計,恐怕很難找到這樣的問題,傳統的Code Review也很難做到這一點。任何一段代碼都至少被兩雙眼睛看過,兩個腦袋思考過,代碼的品質會得到有效提高。
7.時間表
PSP2.1 | Personal Software Process Stages | Time Senior Student(h) | Time(h) |
Planning | 計劃 | 3 | 2 |
· Estimate | 估計這個任務需要多少時間 | 10 | 20 |
Development | 開發 | 8 | 11 |
· Analysis | 需求分析 (包括學習新技術) | 1 | |
· Design Spec | 生成設計文檔 | ||
· Design Review | 設計複審 | ||
· Coding Standard | 代碼規範 | 0.5 | |
· Design | 具體設計 | 4 | 2.5 |
· Coding | 具體編碼 | 12 | 15 |
· Code Review | 代碼複審 | ||
· Test | 測試(自我測試,修改代碼,送出修改) | 1.5 | |
Reporting | 報告 | ||
· | 測試報告 | ||
計算工作量 | |||
并提出過程改進計劃 |