201571030316/201571030314《小學生四則運算練習軟件》結對項目報告
github代碼地址:https://github.com/mqqgd/Experiment2
小夥伴兒的博客地址鏈接:http://www.cnblogs.com/mjuan/p/8715700.html
我的學號:201571030316 小伴兒的學號:201571030314
一、需求分析
本次實驗采用結對編程方式,設計開發一個小學生四則運算練習軟件,使之具有以下功能:
- 由計算機從題庫文件中隨機選擇20道加減乘除混合算式,用戶輸入算式答案,程序檢查答案是否正確,每道題正確計5分,錯誤不計分,20道題測試結束後給出測試總分;
- 題庫文件可采用實驗二的方式自動生成,也可以手工編輯生成,文本格式如下:
- 程序為用戶提供三種進階四則運算練習功能選擇:百以內整數算式(必做)、帶括號算式、真分數算式練習;
- 程序允許用戶進行多輪測試,提供用戶多輪測試分數柱狀圖,示例如下:
- 程序記錄用戶答題結果,當程序退出再啟動的時候,可為用戶顯示最後一次測試的結果,並詢問用戶可否進行新一輪的測試;
- 測試有計時功能,測試時動態顯示用戶開始答題後的消耗時間。
- 程序人機交互界面是GUI界面(WEB頁面、APP頁面都可),界面支持中文簡體(必做)/中文繁體/英語,用戶可以進行語種選擇。
二、軟件設計類圖
三、核心功能代碼展示
1 import java.util.Random; 2 3 public隨機出題class GetRandomDigit { 4 private Random random; 5 public GetRandomDigit(){ 6 random=new Random(); 7 } 8 int oprator(){ 9 return random.nextInt(4)+1; 10 } 11 int Time(){ 12 return random.nextInt(3)+3; 13 } 14 int randomDigit(){ 15 returnrandom.nextInt(100); 16 } 17 int probabilityQuestion(){ 18 return random.nextInt(200); 19 } 20 int BracketsIndex(int time){ 21 return random.nextInt(time-2); 22 } 23 }
1 public class LinkSql { 2 private static final String url = "jdbc:mysql://127.0.0.1:3306/mqqgd"; 3 private static final String user = "root"; 4 private static final String password = "root"; 5 private static ResultSet ret = null; 6 private static final String name = "com.mysql.jdbc.Driver"; 7 public Connection conn = null; 8 public PreparedStatement pst = null; 9 public LinkSql() { 10 try { 11 Class.forName(name);//指定連接類型 12 conn = DriverManager.getConnection(url, user, password);//獲取連接 13 System.out.println("數據庫鏈接成功"); 14 } catch (Exception e) { 15 e.printStackTrace(); 16 } 17 } 18 19 public void changeMySqlDate(String sql) { 20 try { 21 pst=conn.prepareStatement(sql); 22 pst.executeUpdate(); 23 System.out.println("接收到修改數據庫命令"+sql); 24 } catch (SQLException e) { 25 // TODO Auto-generated catch block 26 e.printStackTrace(); 27 } 28 } 29 public ResultSet selectSqlDate(String sql) { 30 try { 31 System.out.println("接收到查詢數據庫命令"+sql); 32 pst=conn.prepareStatement(sql); 33 ret = pst.executeQuery(); 34 return ret; 35 } catch (SQLException e) { 36 // TODO Auto-generated catch block 37 e.printStackTrace(); 38 return null; 39 } 40 } 41 public void closeMySql() { 42 try { 43 this.conn.close(); 44 } catch (SQLException e) { 45 e.printStackTrace(); 46 } 47 } 48 @SuppressWarnings("static-access") 49 public void closeChart() { 50 try { 51 this.pst.close(); 52 this.ret.close(); 53 } catch (SQLException e) { 54 e.printStackTrace(); 55 } 56 } 57 }鏈接數據庫
1 import java.util.HashMap; 2 import java.util.Stack; 3 public class ArithmeticResult { 4 public Double Result(String formula) { 5 Stack<Double> s1 = new Stack<Double>(); 6 Stack<String> s2 = new Stack<String>(); 7 HashMap<String, Integer> hashMap = new HashMap<String, Integer>(); 8 hashMap.put("(", 0); 9 hashMap.put("+", 1); 10 hashMap.put("-", 1); 11 hashMap.put("×", 2); 12 hashMap.put("÷", 2); 13 for (int i = 0; i < formula.length();) { 14 StringBuffer digit = new StringBuffer(); 15 char c = formula.charAt(i); 16 while (Character.isDigit(c) || c == ‘.‘) { 17 digit.append(c); 18 i++; 19 c = formula.charAt(i); 20 } 21 if (digit.length() == 0) { 22 switch (c) { 23 case ‘(‘: { 24 s2.push(String.valueOf(c)); 25 break; 26 } 27 case ‘)‘: { 28 String stmp = s2.pop(); 29 while (!s2.isEmpty() && !stmp.equals("(")) { 30 double a = s1.pop(); 31 double b = s1.pop(); 32 double sresulat = calcDouble(b, a, stmp); 33 s1.push(sresulat); 34 stmp = s2.pop(); 35 } 36 break; 37 } 38 case ‘=‘: { 39 String stmp; 40 while (!s2.isEmpty()) { 41 stmp = s2.pop(); 42 double a = s1.pop(); 43 double b = s1.pop(); 44 double sresulat = calcDouble(b, a, stmp); 45 s1.push(sresulat); 46 } 47 break; 48 } 49 default: { 50 String stmp; 51 while (!s2.isEmpty()) { 52 stmp = s2.pop(); 53 if (hashMap.get(stmp) >= hashMap.get(String.valueOf(c))) { 54 double a = s1.pop(); 55 double b = s1.pop(); 56 double sresulat = calcDouble(b, a, stmp); 57 s1.push(sresulat); 58 59 } else { 60 s2.push(stmp); 61 break; 62 } 63 64 } 65 s2.push(String.valueOf(c)); 66 break; 67 } 68 } 69 } else { 70 s1.push(Double.valueOf(digit.toString())); 71 continue; 72 } 73 i++; 74 } 75 return s1.peek(); 76 } 77 78 public double calcDouble(double a, double b, String stmp) { 79 double res = 0f; 80 char s = stmp.charAt(0); 81 switch (s) { 82 case ‘+‘: 83 res = a + b; 84 break; 85 case ‘-‘: 86 res = a - b; 87 break; 88 case ‘ב: 89 res = a * b; 90 break; 91 case ‘÷‘: 92 res = a / b; 93 break; 94 } 95 return res; 96 } 97 }計算過程
1 //從這裏開始 2 CategoryPlot plot=chart.getCategoryPlot();//獲取圖表區域對象 3 CategoryAxis domainAxis=plot.getDomainAxis(); //水平底部列表 4 domainAxis.setLabelFont(new Font("黑體",Font.BOLD,14)); //水平底部標題 5 domainAxis.setTickLabelFont(new Font("宋體",Font.BOLD,12)); //垂直標題 6 ValueAxis rangeAxis=plot.getRangeAxis();//獲取柱狀 7 rangeAxis.setLabelFont(new Font("黑體",Font.BOLD,15)); 8 chart.getLegend().setItemFont(new Font("黑體", Font.BOLD, 15)); 9 chart.getTitle().setFont(new Font("宋體",Font.BOLD,20));//設置標題字體 10 11 //到這裏結束,雖然代碼有點多,但只為一個目的,解決漢字亂碼問題 12 //這裏也可以用chartFrame,可以直接生成一個獨立的Frame 13 frame1=new ChartPanel(chart,true); 14 15 } 16 17 private CategoryDataset getDataSet() { 18 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 19 System.out.println(times); 20 for(int i=0;i<times;i++){ 21 System.out.println("lalal"); 22 dataset.addValue(result[i],"第"+(i+1)+"輪","第"+(i+1)+"輪"); 23 } 24 return dataset; 25 } 26 27 public ChartPanel getChartPanel(){ 28 return frame1; 29 } 30 }繪制柱狀圖
1 import javax.swing.JFrame; 2 3 @SuppressWarnings("serial") 4 public class Tongji extends JFrame{ 5 PieChart pic; 6 int time; 7 int [] result; 8 public Tongji(int[] result,int time){ 9 this.time=time; 10 this.result=result; 11 setFrame(); 12 } 13 14 //登陸界面 15 private void setFrame(){ 16 System.out.println(time); 17 pic=new PieChart(result,time); 18 this.setTitle("您最終的得分統計"); 19 this.setSize(600,400); 20 this.setLocationRelativeTo(null); 21 this.setResizable(false); 22 this.setVisible(true); 23 this.add(pic.getChartPanel()); 24 25 } 26 }統計分數
四、程序運行
1.登錄界面
2.數據庫
3.做題界面
4.答題結束時,自動顯示柱狀圖
五、結對過程
六、PSP
PSP2.1 |
任務內容 |
計劃共完成需要的時間(min) |
實際完成需要的時間(min) |
Planning |
計劃 |
20 |
16 |
· Estimate |
· 估計這個任務需要多少時間,並規劃大致工作步驟 |
20 |
16 |
Development |
開發 |
1838 |
1736 |
·· Analysis |
需求分析 (包括學習新技術) |
20 |
20 |
· Design Spec |
· 生成設計文檔 |
25 |
25 |
· Design Review |
· 設計復審 (和同事審核設計文檔) |
10 |
10 |
· Coding Standard |
代碼規範 (為目前的開發制定合適的規範) |
3 |
3 |
· Design |
具體設計 |
300 |
240 |
· Coding |
具體編碼 |
1440 |
1400 |
· Code Review |
· 代碼復審 |
10 |
8 |
· Test |
· 測試(自我測試,修改代碼,提交修改) |
30 |
30 |
Reporting |
報告 |
33 |
30 |
·· Test Report |
· 測試報告 |
3 |
2 |
· Size Measurement |
計算工作量 |
10 |
8 |
· Postmortem & Process Improvement Plan |
· 事後總結 ,並提出過程改進計劃 |
20 |
20 |
七、用漢堡評價法給小夥伴的點評
首先很感謝我的小夥伴,在這次結對過程中對我的幫助。我是個比較懶的人,每次作業都很喜歡拖到最後一天寫,但是我的小夥伴兒督促我,我們一起完成任務。我和小夥伴在編程方面是個newbie??,當老師布置任務以後,我和小夥伴有些絕望,最後想了想,反正也躲不過??,還是乖乖做吧??。我們請教大神,在網上查找資料,看看那些早早做完作業的同學的作業,摸索著思考著我們的作業該如何做如何設計。在合作的過程中,我們不斷的互換角色,誰也記不清哪行代碼是誰敲的??我們之間也沒有出現各執己見的情況,很感謝我的小夥伴,我們都用“橋梁”的方式(ps:在鄒欣老師的博文中有詳細的介紹),給彼此充分的條件相互了解,達成共識。
八、結對編程真的能夠帶來1+1>2的效果嗎?通過這次結對編程,請談談你的感受和體會
通過這次和小夥伴結對完成這個任務,我覺得結對編程真的能帶來1+1>2的效果。以前自己一個人在寫作業的時候,遇到困難時並沒有及時去解決問題,而是和朋友扣扣,淘淘寶或者幹幹其他事,最後什麽都沒幹,白天的任務拖到晚上熬夜做,看起來我很用功似的。這次結對編程對我的幫助很大,我和小夥伴共用一臺電腦,相互督促,在做作業的時候沒有做和作業無關的事,我也沒有熬夜做作業^o^,上課也精神滿滿^0^~~而且,上次沒有實現的括號運算,我和小夥伴一起請教班裏的大神,最後也完成了。很感謝我的小夥伴,我們班的大神,還有老師們,嘿嘿,總之,這次結對感覺很棒棒~
參考資料:
http://www.cnblogs.com/xinz/archive/2011/08/22/2148776.html
https://baike.baidu.com/item/%E7%BB%93%E5%AF%B9%E7%BC%96%E7%A8%8B/7526152?fr=aladdin
201571030316/201571030314《小學生四則運算練習軟件》結對項目報告