四则运算结对编程
GitHub項目地址:https://github.com/Juneflyfire/jisuan2
a. 需求分析:
設(shè)計開發(fā)一個小學(xué)生四則運算練習(xí)軟件,使之具有以下功能:
(1)由計算機從題庫文件中隨機選擇20道加減乘除混合算式,用戶輸入算式答案,程序檢查答案是否正確,每道題正確計5分,錯誤不計分,20道題測試結(jié)束后給出測試總分;
(2)題庫文件可采用實驗二的方式自動生成,也可以手工編輯生成
(3)程序為用戶提供三種進階四則運算練習(xí)功能選擇:百以內(nèi)整數(shù)算式(必做)、帶括號算式、真分?jǐn)?shù)算式練習(xí);
(4)程序允許用戶進行多輪測試,提供用戶多輪測試分?jǐn)?shù)柱狀圖;
(5)程序記錄用戶答題結(jié)果,當(dāng)程序退出再啟動的時候,可為用戶顯示最后一次測試的結(jié)果,并詢問用戶可否進行新一輪的測試;??
(6)測試有計時功能,測試時動態(tài)顯示用戶開始答題后的消耗時間。
(7)程序人機交互界面是GUI界面(WEB頁面、APP頁面都可),界面支持中文簡體(必做)/中文繁體/英語,用戶可以進行語種選擇。
?
b. 軟件設(shè)計:使用類圖
?
c. 核心功能代碼展示:展示核心功能代碼。
(1)語言切換
? ? 以下為語言的切換功能,采用的方式是設(shè)置三個按鈕,分別為“簡體中文”、“繁體中文”和“英文”,將窗體上所有的文字設(shè)置為一個變量,當(dāng)任意一個按鈕按下時,切換成該按鈕對應(yīng)的語言。
if(input.equals("S5"))//簡體中文 {La1="得分";La2="計時";La4="下一輪";La5="提交答案";La6="測評";La7="簡體中文";La8="繁體中文";La9="英文";La10="整數(shù)運算";La11="分?jǐn)?shù)運算"; l1.setText(La1);BT4.setText(La6);BT2.setText(La5);BT5.setText(La7);BT6.setText(La8);BT7.setText(La9);BT8.setText(La2);BT9.setText(La10);BT10.setText(La11);} if(input.equals("S6"))//繁體中文 {La1="得分";La2="計時";La4="下一輪";La5="提交答案";La6="測評";La7="簡體中文";La8="繁體中文";La9="英文";La10="整數(shù)運算";La11="分?jǐn)?shù)運算"; l1.setText(La1);BT4.setText(La6);BT2.setText(La5);BT5.setText(La7);BT6.setText(La8);BT7.setText(La9);BT8.setText(La2);BT9.setText(La10);BT10.setText(La11);} if(input.equals("S7")){La1="Grade";La2="Time";La4="Next Turn";La5="Submit";La6="Measurement";La7="Simplified Chinese";La8="Traditional Chinese";La9="English";La10="Integer arithmetic";La11="Fraction arithmetic"; l1.setText(La1);BT4.setText(La6);BT2.setText(La5);BT5.setText(La7);BT6.setText(La8);BT7.setText(La9);BT8.setText(La2);BT9.setText(La10);BT10.setText(La11); }(2)統(tǒng)計得分
對“提交答案”按鈕進行監(jiān)聽,獲取所有輸入的答案,于文本文檔result1中的答案進行比較,每對一題得五分,在得分后的文本框中顯示得分。
if(input.equals("S2"))//提交答案 {String []res = new String[20];//獲取結(jié)果數(shù)組try {int i = 1;BufferedReader br = new BufferedReader(new FileReader("result1.txt"));String nString = br.readLine();res[0] = nString;while (nString != null) {nString=br.readLine();res[i]= nString;i++;}br.close();} catch (Exception e) { } int sum = 0;//獲取答案內(nèi)容if(a1.getText().equals(res[0])){sum += 5; }if(a2.getText().equals(res[1]))sum += 5;if(a3.getText().equals(res[2]))sum += 5;if(a4.getText().equals(res[3]))sum += 5;if(a5.getText().equals(res[4]))sum += 5;if(a6.getText().equals(res[5]))sum += 5;if(a7.getText().equals(res[6]))sum += 5;if(a8.getText().equals(res[7]))sum += 5;if(a9.getText().equals(res[8]))sum += 5;if(a10.getText().equals(res[9]))sum += 5;if(a11.getText().equals(res[10]))sum += 5;if(a12.getText().equals(res[11]))sum += 5;if(a13.getText().equals(res[12]))sum += 5;if(a14.getText().equals(res[13]))sum += 5;if(a15.getText().equals(res[14]))sum += 5;if(a16.getText().equals(res[15]))sum += 5;if(a17.getText().equals(res[16]))sum += 5;if(a18.getText().equals(res[17]))sum += 5;if(a19.getText().equals(res[18]))sum += 5;if(a20.getText().equals(res[19]))sum += 5;String sco = sum + "";l2.setText(sco);Grade.add(sco);}(3)計時
public class Time extends JFrame {private static final long serialVersionUID = 1L; private static final String INITIAL_LABEL_TEXT = "00:00:00 000"; // 計數(shù)線程 private CountingThread thread = new CountingThread(); // 記錄程序開始時間 private long programStart = System.currentTimeMillis(); // 程序一開始就是暫停的 private long pauseStart = programStart; // 程序暫停的總時間 private long pauseCount = 0; private JLabel label = new JLabel(INITIAL_LABEL_TEXT); private JButton startPauseButton = new JButton("開始"); private JButton resetButton = new JButton("清零"); String time;private ActionListener startPauseButtonListener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (thread.stopped) { pauseCount += (System.currentTimeMillis() - pauseStart); thread.stopped = false; startPauseButton.setText("暫停"); } else { pauseStart = System.currentTimeMillis(); thread.stopped = true; startPauseButton.setText("繼續(xù)"); } } }; private ActionListener resetButtonListener = new ActionListener() { public void actionPerformed(ActionEvent e) { pauseStart = programStart; pauseCount = 0; thread.stopped = true; label.setText(INITIAL_LABEL_TEXT); startPauseButton.setText("開始"); } }; public Time(String title) throws HeadlessException { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocation(300, 300); setResizable(false); setupBorder(); setupLabel(); setupButtonsPanel(); startPauseButton.addActionListener(startPauseButtonListener); resetButton.addActionListener(resetButtonListener); thread.start(); // 計數(shù)線程一直就運行著 } // 為窗體面板添加邊框 private void setupBorder() { JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); this.setContentPane(contentPane); } // 配置按鈕 private void setupButtonsPanel() { JPanel panel = new JPanel(new FlowLayout()); panel.add(startPauseButton); panel.add(resetButton); add(panel, BorderLayout.SOUTH); } // 配置標(biāo)簽 private void setupLabel() { label.setHorizontalAlignment(SwingConstants.CENTER); label.setFont(new Font(label.getFont().getName(), label.getFont().getStyle(), 40)); this.add(label, BorderLayout.CENTER); } private class CountingThread extends Thread { public boolean stopped = true; private CountingThread() { setDaemon(true); } @Override public void run() { while (true) { if (!stopped) { long elapsed = System.currentTimeMillis() - programStart - pauseCount; label.setText(format(elapsed)); time=label.getText();File f=new File("time.txt");BufferedWriter bw;try {bw = new BufferedWriter(new FileWriter(f));bw.write(time);bw.close();} catch (IOException e) {// TODO Auto-generated catch block e.printStackTrace();}} try { sleep(1); // 1毫秒更新一次顯示 } catch (InterruptedException e) { e.printStackTrace(); System.exit(1); } } } // 將毫秒數(shù)格式化 private String format(long elapsed) { int hour, minute, second, milli; milli = (int) (elapsed % 1000); elapsed = elapsed / 1000; second = (int) (elapsed % 60); elapsed = elapsed / 60; minute = (int) (elapsed % 60); elapsed = elapsed / 60; hour = (int) (elapsed % 60); return String.format("%02d:%02d:%02d:%03d", hour, minute, second, milli); } } }(4)柱狀圖
public class BarGraph extends JPanel {private int x;private static int length ; int i=0;public int[] count;ArrayList<JLabel> label = new ArrayList<JLabel>();public BarGraph(final ArrayList<String> summer) {length = summer.size();count = new int[length];System.out.print(length);this.setLayout(null);for(int i=0;i<summer.size();i++){count[i] = Integer.parseInt(summer.get(i)); }for(int i=1;i<summer.size();i=i+2){JLabel Label = new JLabel("柱狀圖",JLabel.LEFT);Label.setFont(new Font("SansSerif", Font.BOLD + Font.ITALIC, 18));Label.setBounds(30+(i-1)*30, 610, 60,50);JLabel Label2 = new JLabel(count[i]+"",JLabel.CENTER);Label2.setFont(new Font("SansSerif", Font.BOLD + Font.ITALIC, 18));Label2.setBounds(25+(i-1)*30, 555-6*count[i], 60,50);label.add(Label);label.add(Label2);this.add(label.get(i-1));this.add(label.get(i)); }} protected void paintComponent(Graphics g) {int x=10;g.setColor(Color.red);for (int i = 0; i < count.length; i++) { g.fillRect(x, 600-6*count[i], 30,6*count[i] );x += 30; }} }?
d. 程序運行:程序運行時每個功能界面截圖。
(1)語言的切換
(2)點擊“整數(shù)運算”按鈕以后,隨機產(chǎn)生20個算式,并且存在result文本文檔中,同時將單獨的計算結(jié)果存在result1文檔中。如下圖所示:
‘’
(3)計時。點擊“計時”按鈕,開始計時,當(dāng)答案輸入完畢時,提交答案,顯示得分。計時器具有清零、暫停等按鈕。
?
?
(4)柱狀圖
第一輪計算
?
第二輪, 再次點擊“整數(shù)運算”按鈕,將上一輪的文本框清空,進行再一輪運算。
將以上兩輪的得分存在一個ArrayList數(shù)組中,作為繪制柱狀圖的參數(shù)
?
?
e.描述結(jié)對的過程,提供兩人在討論、細(xì)化和編程時的結(jié)對照片(非擺拍)。
由于我們采用的是分工合作的方法完成項目,彼此不熟悉彼此的代碼風(fēng)格,兩個人也沒有花時間去討論類與類之間的關(guān)系,只是畫了一個初期完成項目的思維導(dǎo)圖就開始各做個的了,再花一天時間一起完善代碼。在這期間,隊友給我?guī)砹撕芏嗟男滤悸?#xff0c;但同時呢,也出現(xiàn)過兩個人彼此誤導(dǎo),在長時間編程以后兩個人都陷入了錯誤之中。兩個人也都在磨合之中,逐漸提高了Java的編程能力。
?
?
f.提供此次結(jié)對作業(yè)的PSP。
| PSP2.1 | 任務(wù)內(nèi)容 | 計劃共完成需要的時間(min) | 實際完成需要的時間(min) |
| Planning | 計劃 | 8 | 6 |
| ·?????? Estimate | ·? 估計這個任務(wù)需要多少時間,并規(guī)劃大致工作步驟 | 8 | 6 |
| Development | 開發(fā) | 600 | 1800 |
| ··?????? Analysis | ? 需求分析 (包括學(xué)習(xí)新技術(shù)) | 6 | 10 |
| ·?????? Design Spec | ·? 生成設(shè)計文檔 | 5 | 6 |
| ·?????? Design Review | ·? 設(shè)計復(fù)審?(和同事審核設(shè)計文檔) | 4 | 6 |
| ·?????? Coding Standard | ? 代碼規(guī)范?(為目前的開發(fā)制定合適的規(guī)范) | 3 | 3 |
| ·?????? Design | ? 具體設(shè)計 | 10 | 12 |
| ·?????? Coding | ? 具體編碼 | 36 | 1693 |
| ·?????? Code Review | ·? 代碼復(fù)審 | 7 | 10 |
| ·?????? Test | ·? 測試(自我測試,修改代碼,提交修改) | 13 | 60 |
| Reporting | 報告 | 9 | 6 |
| ··?????? Test Report | ·? 測試報告 | 3 | 2 |
| ·?????? Size Measurement | ? 計算工作量 | 2 | 1 |
| ·?????? Postmortem & Process Improvement Plan | ·? 事后總結(jié)?,并提出過程改進計劃 | 3 | 3 |
g. 請使用漢堡評價法給你的小伙伴一些點評。
隊友是個好隊友,思路很清晰,效率也很高。在兩個人的思想碰撞中,可以很好的表達自己,并且讓我很好的接受她的建議。希望在未來還有機會可以一起合作。
h. 結(jié)對編程真的能夠帶來1+1>2的效果嗎?通過這次結(jié)對編程,請談?wù)勀愕母惺芎腕w會。
結(jié)對編程可以帶來1+1>2的效果,因為自己在編寫代碼的時候,很容易陷入錯誤的思路之中,此時隊友就可以在一旁點醒自己。兩個人編程可以取長補短,相互補充不知道的知識,同時也因為分工合作的原因,不自覺地會將代碼規(guī)范,認(rèn)真地將自己寫的代碼部分注釋好意思,并且給隊友講解,在這個過程中,自己對自己的要求高了,知識記憶也加深了。當(dāng)然了,凡事都要兩面性,在與隊友的磨合時,花費了很長的時間,也面臨了與隊友的時間沖突問題,但這些都是可以一一克服的。
很多書中都批判過中國人的合作,《丑陋的中國人》中將這個問題延伸到了“窩里斗”,三個和尚沒水喝的故事也成了合作界的笑話。但是在本次項目中,我切身體會到了“三個臭皮匠賽過諸葛亮”的道理。在信息大爆炸的今天,只有合作,才能讓思想之花綻放的燦爛,中國的互聯(lián)網(wǎng)飛速發(fā)展,大家都在提倡團隊合作,我們再也不是像曾經(jīng)書中寫的那樣了。
至于自己在寫代碼的過程中,最大的感悟就是前期的分析工作是至關(guān)重要的,由于沒有提前設(shè)計好項目思路,在寫項目尤其是在寫界面的時候,反復(fù)改寫界面,類寫了又刪,刪了又寫,而且對于用戶的需求分析不足,只關(guān)注到了老師留的任務(wù)的個數(shù),想著將任務(wù)全部完成,卻忽視了小學(xué)生是多數(shù)用戶,在寫的時候犯下了致命錯誤,就是沒有控制百內(nèi)的整數(shù)運算。雖然功能基本完成,但是卻是很失敗的。其次就是,條條大路通羅馬,在編寫代碼的過程中,會遇到一個方法行不通,然后又想著可以存在文檔里,再行不通的話又會想出另一個辦法,實現(xiàn)同一個功能,會有很多很多的方法去達到它,這大概也是它的迷人之處吧,讓編程者在思考的海洋中不斷遨游。最后就是,少壯不努力,老大徒傷悲呀,大一Java沒學(xué)好,現(xiàn)在每次項目前,都需要把代碼涉及到的知識點都現(xiàn)學(xué)一遍,所幸的是,現(xiàn)在的自己,已經(jīng)可以靜下心來花很長的時間去寫一個代碼,所幸的是,現(xiàn)在也不晚。
?
轉(zhuǎn)載于:https://www.cnblogs.com/wuqiong666/p/8711128.html
總結(jié)
- 上一篇: MySQL用户管理及SQL入门
- 下一篇: Selenium 基于python 安