1. 程式人生 > >結隊編程-WordCount

結隊編程-WordCount

content report 事件 總結 就是 select action string setw

合作者:

201631062201,201631062202


代碼地址:

https://gitee.com/ZMLJZ/codes/3os7pwfqz58unil9c1xag30#WordCount.java


作業鏈接:

https://edu.cnblogs.com/campus/xnsy/2018Systemanalysisanddesign/homework/2188


代碼審核及合並

回觀我們的第一次項目,我們都並沒自審我們的代碼,也沒有做很嚴謹的測試。結對項目中我們相互對對方的代碼進行了審核,張明磊同學認為奐欣同學的代碼,將所有的任務都放在了主函數裏,造成依賴過重,奐欣同學認為張明磊同學的代碼代碼結構挺好的,但是不夠完善,讀取文件那裏有待改進。最後兩個人將代碼合並實現該項目的擴展和高級功能。

具體的審核如下表:

代碼自審

代碼互審

代碼合並

獨自檢查文件名,邏輯、以及是否存在不合法的操作

首先運行代碼,查看代碼是否可以通過並達到預期的目的。

將自審和互審的結果進行討論,把穩定的部分代碼進行標記,提出各自認為好的模塊,參考對方的代碼進行比較,把穩定性高,更加好的的代碼

留下,並在任一一個項目上進行合並,最後兩人一起完成審核,測試,並完成擴展功能

檢查代碼在編碼格式,代碼結構上是否存在問題。

其次是構建測試類,調用關鍵的方法去執行,查看是否能通過運行或者拋出異常

檢查在關鍵代碼上是否有異常拋出

最後就是測試代碼的穩定性,通過多個文件對代碼進行測試,查看是否出現異常


(1)PSP表格

PSP2.1

PSP階段

預估耗時(分鐘)

實際耗時(分鐘)

Planning

計劃

100

300

Estimate

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

120

100

Development

開發

500

1000

Analysis

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

180

300

Design Spec

生成設計文檔

80

90

Design Review

設計復審(和同事審核設計文檔)

60

30

Coding Standard

代碼規範(為目前的開發指定合適的規範)

90

150

Design

具體設計

200

240

Coding

具體編碼

400

480

Code Review

代碼復審

180

210

Test

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

200

250

Reporing

報告

20

60

Test Report

測試報告

30

50

Size Measurement

計算工作量

30

50

Postmortem&Process Improvement Plan

事後總結,並提出過程改進計劃

30

60

合計

2220

3370


代碼說明

統計文件字符的相關代碼:根據符號將文本分割,分別統計字符數,單詞數和行數

	public void doCount(String inputFile) throws IOException {
		String txt = "";
		String[] buffer;
		File dir = new File(inputFile);
		BufferedReader bf = new BufferedReader( new FileReader(dir) );
		while( (txt = bf.readLine()) != null ){
              buffer = txt.split(", |  |\t |\n");//根據字符切分
              for(int i = 0 ; i < buffer.length ; i++){
                  if( !buffer[i].equals(""))
                    count.setWordNumber( count.getWordNumber()+1 );//統計單詞數
              }
              count.setLineNumber( count.getLineNumber()+1 );//統計行數
              count.setCharNumber( count.getCharNumber() + txt.length() );//統計字符數
        }
          bf.close();
	}

    

創建窗口並設置兩個按鈕

                CrateJFrame(title);
		c = jf.getContentPane();
		setLayout();    

  

		JButton choseFile = new JButton("選擇文件");
		choseFile.addActionListener(new choseFileAction());
		c.add(choseFile);
		
		JButton outputFile = new JButton("生成統計文件");
		outputFile.addActionListener(new outputFileAction());
		c.add(outputFile);
		

  

利用內部類設置按鈕的監聽事件,選擇文件是記錄所選擇的文件路徑,生成統計文件是根據所選擇的文件生成一個存有統計結果的文件:

	class choseFileAction implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
		JFileChooser jfc=new JFileChooser();  
	        jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );  
	        jfc.showDialog(new JLabel(), "選擇");
	        File file=jfc.getSelectedFile();
			
	        inputFile = file.getAbsolutePath();
	        fileName = file.getName();
		}
	}
	
	class outputFileAction implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0){
			
			try {
				//讀入test.c文件
				String inputFile = getInputFile();
				WordCount wc = new WordCount();
				wc.doCount(inputFile);
				String output = inputFile.replace(".", "_output.");
				
				//將結果寫入output.txt
				File resultFile = new File(output);
				resultFile.createNewFile();
				
				BufferedWriter out = new BufferedWriter( new FileWriter(resultFile) );
				out.write("字符數:"+wc.getCount().getCharNumber());
				out.newLine();
				out.write("單詞數:"+wc.getCount().getWordNumber());
				out.newLine();
				out.write("行數:"+wc.getCount().getLineNumber()); 
				
				out.flush(); 
				out.close(); 
				
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

運行效果:

技術分享圖片

選擇文件

技術分享圖片

生產的統計文件都保存在選擇文件同目錄下:

技術分享圖片

Txt文件

技術分享圖片


總結:

一個人做確實比不上結對的效率,互審可以比自審更加清楚的發現自己的問題,遇到了問題也可以更好的給予幫助,因為是兩個人,不容易產生分歧,面對小問題也更容易想到解決辦法。

結隊編程-WordCount