結對作業 肖榮森(201421123079) 蘇上鑫(201421123081)

需求分析:

 

不知道大家是否嘗試過這樣一種開發模式:你有一個夥伴,你們坐在一起,並肩作戰,面對着同一臺顯示器,使用着同一鍵盤,同一個鼠標,你們一起思考,一起分析,一起編程?這次,就讓我們來體驗一下結對編程的魅力:
http://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html

我們在個人作業1中,用各種語言實現了一個命令行的四則運算小程序。進一步,本次要求把這個程序做成GUI(可以是Windows PC 上的,也可以是Mac、Linux,web,手機上的),成爲一個有基本功能、一定價值的程序。在下面的功能需求中實現兩個:

  1. 記錄用戶的對錯總數,程序退出再啓動的時候,能把以前的對錯數量保存並在此基礎上增量計算。
  2. 有計時功能,能顯示用戶開始答題後的消耗時間。
  3. 界面支持中文簡體/中文繁體/英語,用戶可以選擇一種;

在軟件開發中,我們需要大量使用工具來輔助設計,每個環節大家都要善於學習和使用工具。設計的時候,請使用思維導圖設計你的模塊之間的關係,參考這位同學的思維導圖:

http://www.cnblogs.com/hts-technology/p/6490667.html

程序設計:

    1. 一個小組中的兩個同學選取比較優秀的 作業1 (兩個人的都獨立完成了), 把它作爲本次作業的基礎,然後再修改。
    2. 結對編程實現上述功能,同樣的,在程序正式開發之前,請先預估下PSP每個環節的消耗時間,並在過程中統計實際耗時,最後提交PSP表格。依然注意,這個主要是給你們自己看的,不必造假數據。
    3. 在兩人合作的過程中, 請看下面的內容

      a. 滿足代碼風格規範和代碼設計規範(參考書第4章4.1-4.3內容)http://www.cnblogs.com/xinz/archive/2011/11/20/2255971.html
      - 請重視這點,在開發時兩個人要有口頭上的溝通:「好的,我們一起在開發中遵守一起認可的編碼規範」
      - 請把你們約定的編碼規範文檔也提交到git

      b. 給人提意見的方式——送一個漢堡包http://www.cnblogs.com/xinz/archive/2011/08/22/2148776.html

      c. 理解領航員和駕駛員兩種角色關係,並在結對編程中兩個人輪流做對方的角色。兩人都必須參與本次作業的編碼工作,並在git提交日誌上體現這點。

代碼展示:

static randomTest produce= new randomTest();
    Vector answer = new Vector();
    Vector expression=new Vector();
    Vector result=new Vector();
    int x=0;
    int time =0;
    Endjframe submit=new Endjframe();
    
    public GUI() {
        initComponents();
    }
    public void produceExpression()
    { 
        produce.randTest();
        expression.add(produce.Expression);
        result.add(produce.calc);
    }
    public void judge()
    {       
        for(int i=0;i<Integer.parseInt(jTextField1.getText());i++)
        {
            if(answer.get(i).equals(result.get(i)))
                x++;
        }
    }
    public void MyTask()
    {
        time++;
        jLabel3.setText(Integer.toString(time%3600));
        jLabel4.setText(Integer.toString(time%60));
        jLabel4.setText(Integer.toString(time/60));
    }
複製代碼

judge在兩個向量中的元素判斷是否相等,produceExpression用來生成式子的答案放入向量中;

 

Endjframe類用來展示正確答案以及輸入的答案,並對錯誤的題目進行統計

複製代碼
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sizeyunsuan;

/**
 *
 * @author Overwhelming
 */
public class Endjframe extends javax.swing.JFrame {

    /**
     * Creates new form Endjframe
     */
    public Endjframe() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jTextArea3.setColumns(20);
        jTextArea3.setRows(5);
        jScrollPane3.setViewportView(jTextArea3);

        jLabel1.setText("正確");

        jLabel2.setText("錯誤");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jTextField1, jTextField2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(43, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41))))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel2, jTextField1, jTextField2});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Endjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Endjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Endjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Endjframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Endjframe().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JLabel jLabel1;
    public static javax.swing.JLabel jLabel2;
    public static javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JScrollPane jScrollPane2;
    public static javax.swing.JScrollPane jScrollPane3;
    public static javax.swing.JTextArea jTextArea1;
    public static javax.swing.JTextArea jTextArea2;
    public static javax.swing.JTextArea jTextArea3;
    public static javax.swing.JTextField jTextField1;
    public static javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}
複製代碼

程序運行:

 

小結感受:

此次實驗是第一次團隊合作,在一些問題的處理上,可以相互幫助,使得代碼的實現比單人的更順利,深刻體會到團隊合作的重要性,爲以後工作打下一點基礎。

團隊圖片:

 

PSP:

PSP2.1

Personal Software Process Stages

Time (%) Senior Student

Time (%)

Planning

計劃

10

15

· Estimate

估計這個任務需要多少時間

5

200

Development

開發

10

30

· Analysis

需求分析 (包括學習新技術)

5

5

· Design Spec

生成設計文檔

3

5

· Design Review

設計複審

0

0

· Coding Standard

代碼規範

3

10

· Design

具體設計

10

20

· Coding

具體編碼

50

150

· Code Review

代碼複審

5

5

· Test

測試(自我測試,修改代碼,提交修改)

10

5

Reporting

報告

2

20

·

測試報告

1

5

·

計算工作量

1

5

·

並提出過程改進計劃

3

2

 

 

 

coding:https://coding.net/u/theouts/p/produceExpressionGUI