碼雲地址:https://gitee.com/NiBiWoWuLiao/PairProject-Javahtml
結對小夥伴姓名:林文秀
學號:201621123003
博客地址:http://www.javashuo.com/article/p-xxnjkmfg-b.htmlgit
碼雲截圖:
數組
PSP2.1 | 開發流程 | 預估耗費時間(分鐘) | 實際耗費時間(分鐘) |
---|---|---|---|
Planning | 計劃 | 30 | 25 |
· Estimate | 明確需求和其餘相關因素,估計每一個階段的時間成本 | 10 | 20 |
Development | 開發 | 200 | 240 |
· Analysis | 需求分析 (包括學習新技術) | 20 | 20 |
· Design Spec | 生成設計文檔 | 10 | 15 |
· Design Review | 設計複審 | 10 | 45 |
· Coding Standard | 代碼規範 | 30 | 25 |
· Design | 具體設計 | 30 | 50 |
· Coding | 具體編碼 | 150 | 180 |
· Code Review | 代碼複審 | 10 | 15 |
· Test | 測試(自我測試,修改代碼,提交修改) | 30 | 55 |
Reporting | 報告 | 60 | 85 |
· | 測試報告 | 30 | 30 |
· | 計算工做量 | 30 | 25 |
· | 並提出過程改進計劃 | 30 | 15 |
代碼分爲三大類:函數
函數分爲:單元測試
ReadFromFile(String path)//讀取文件學習
public BufferedReader ReadFromFile(String path) throws IOException { //讀取文件 File file = new File(path); if (!file.exists() || file.isDirectory()) { System.out.println("請輸入正確文件名!"); throw new FileNotFoundException(); } InputStreamReader isr = new InputStreamReader(new FileInputStream(path));// 創建一個輸入流對象 BufferedReader br = new BufferedReader(isr); return br; }
WriteToFile(String path,String content)//寫入文件測試
public void WriteToFile(String path,String content) { //寫入文件 try { OutputStream out = new FileOutputStream(path); out.write(content.getBytes()); out.close(); } catch (Exception e) { e.printStackTrace(); } }
Phrase(int number) //統計詞組而且排序編碼
public String Phrase(int number) throws Exception{ if(number>lists.size()){ return "the number is too long"; } String wordGroup[] = new String[lists.size()-number+1]; for (int i = 0; i <lists.size()-number+1 ; i++) { //按number數爲一組加入數組 } Map<String,Integer> treeMap =new TreeMap<String,Integer>(); for (int i = 0; i < wordGroup.length; i++) { String s = wordGroup[i]; if (!treeMap.containsKey(s)) { //不存在 } else { //已經存在 } } List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(treeMap.entrySet()); Collections.sort(list, ((o1, o2) -> o2.getValue().compareTo(o1.getValue()))); String s[] = new String[wordGroup.length]; int i =0; for (Map.Entry<String,Integer>entry:list) { String key = entry.getKey(); Integer value = entry.getValue(); s[i] = key + ": " + value; i++; } String string = s[0]+"\n"; for (int j = 1; j <i ; j++) { string = string + s[j] + "\n"; } return string ; }
演示截圖:在本次演示過程當中文本內容均爲Monday Tuesday Wednesday Thursday設計
輸出三個爲一組的詞組:
3d
輸出出現頻率第一的單詞,並將其寫入文件中
改進思路:根據上週是沒有完成按模塊分寫而將全部的函數都放在Main類中,這周將對文件的操做和對字符的統計操做分紅單個單獨的類。並且本次要求增長的統計新功能有兩個,一是詞組統計,因爲詞組統計就沒辦法再像以前統計單詞同樣根據非數字字母劃分,咱們的想法:根據空格劃分,而後根據詞組的長度進行先拼接存入一個新數組中,而後再去讀這個存放詞組的數組。對於自定義輸出就參照了上週要求輸出前十,修改成自定義輸出要求的個數。
這裏放上類圖:
本次測試的函數着重於新增的詞組部分上週實現的那些就進行了簡單的正確性測試。如圖:
對於按要求輸出詞組的測試分別進行了詞組長度大於或小於或等於單詞長度的三種測試:
測試讀取非根目錄下的本地文件
單元測試覆蓋率圖:
因爲沒有考慮輸入m的數超過了單詞總數報錯:
解決方案並回歸測試: