軟工第二次作業
軟工第二周作業
| 這個作業屬于哪個課程 | https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018 |
|---|---|
| 這個作業要求在哪里 | https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018/homework/11877 |
| 這個作業的目標 | 理解如何在實戰中運用軟件工程這門學科的知識 |
| 其他參考書籍 | 《碼出高效_阿里巴巴Java開發手冊》/《騰訊c++代碼規范》/《Python PEP8》 《廖雪峰git教程》 |
1、git項目代碼地址
https://gitee.com/sunzeliang/project-java/tree/master/
https://gitee.com/sunzeliang/project-java
2、代碼規范制定鏈接
https://gitee.com/sunzeliang/project-java/blob/master/20188413/codestyle.md
3、解題思路與設計實現過程
1、統計文件的字符數
根據編碼判斷每個字符是不是我們所需要的。
2、統計文件的單詞總數
采用正則表達式
3、統計文件的行數
通過readLine()獲取行數
并識別換行符
4、統計單詞頻率,并輸出頻率最高的10個
在分割出單詞之后,將單詞遍歷儲存在hashmap當中,在儲存前先判斷是否為合法單詞
將map的遍歷儲存在set當中
統計字符個數
while((value = bReader.read()) != -1) {
if (value >= 0 && value<=255) {
charcount++; 4 }
}
統計單詞
while ((line = bufferedReader.readLine()) != null) {
String[] words = line.split("[^a-zA-Z0-9]+");
for (String word : words) {
word.toLowerCase();
if (word.matches("[a-zA-Z]{4}[a-zA-Z0-9]*") ) {
countword++;
}
}
}
統計文件行數
while ((line = bufferedReader.readLine()) != null) {
if (line.length() != 0 && !line.matches("\\s+")) {
linecount++;
}
}
得出單詞頻率最高的十個單詞
在分割出單詞之后,將單詞遍歷儲存在hashmap當中,在儲存前先判斷是否為合法單詞
String str=st.nextToken();
str = str.toLowerCase();
if ((str.charAt(0) >= '9' || str.charAt(0) <= '0') && str.length() >= 4) {
if(map.containsKey(str))
map.put(str, map.get(str)+1);
else map.put(str, 1);}
將map的遍歷儲存在set當中
Set<WordEntity> set=new TreeSet<WordEntity>();
for(String s:map.keySet()){
WordEntity wordEntry=new WordEntity(s,map.get(s));
set.add(wordEntry);
}
Iterator<WordEntity> ite=set.iterator();
int count=0;
while(ite.hasNext()){
if(count>=10)
break;
System.out.println(ite.next());
count++;
}
性能改進
從最初的暴力解決一步步改善用hashmap存儲對單詞的遍歷,map的遍歷存儲在set中,排序 TreeSet,對wordEntity實現comparable接口重寫compareTo()和toString()。
@Override
public String toString() {
writeInTxt.writeTxt( "<" + word + ">:" + count);
return "<" + word + ">:" + count;
}
@Override
public int compareTo(WordEntity O) {
int cmp=count.intValue()-O.count.intValue();
return (cmp==0?word.compareTo(O.getKey()):-cmp);
}
接口
public interface WordCount {
/**
* 返回行數
* @param filename
* @return
* @throws IOException
*/
int linesCount(String filepath) throws IOException;
/**
* 返回合法單詞數
* @param filepath
* @return
* @throws IOException
*/
int wordsCount(String filepath) throws IOException;
/**
* 返回字符數
* @param filepath
* @return
* @throws IOException
*/
int charsCount(String filepath) throws IOException;
/**
* 詞頻前十的單詞
* @param filepath
* @throws IOException
*/
void wordDetail(String filepath) throws IOException;
}
單元測試


代碼覆蓋率

異常處理說明
try{
可能發生異常的代碼塊
}catch(異常1){
處理異常1的代碼
}
計算模塊異常,可能導致文件不存在。
心路歷程與收獲
對于本次作業還感到自己有很多的不足之處,還需努力學習,對于一些技術的用法還掌握的不夠。還得深造。而且在完成本次作業的時候,感覺很吃力。沒有之前那么輕松了,這次真正認識到的書到用時方恨少。
也感受到了平時學習和積累的重要性。通過這次之后,我會擠出一部分課余時間來進行課外知識的學習。對于java的學習更要努力了。不過對git的指令越來越熟悉了。對于一些知識也有了一定的了解。在此次作業之后,
定要回顧一下Java開發實戰經典這本書。以及努力學習一下python。
PSP表格
| PSP2.1 | Personal Software Process Stages | 預估時間(分鐘) | 實際消耗(分鐘) |
|---|---|---|---|
| Planning | 計劃 | 20 | 30 |
| Estimate | 估計這個任務需要多少時間 | 10 | 20 |
| Development | 開發 | 400 | 650 |
| Analysis | 需求分析(包括學習新的資料) | 60 | 180 |
| Design Spec | 生成設計文檔 | 15 | 20 |
| Design Review | 設計復審 | 20 | 10 |
| Coding Standard | 代碼規范(為目前的開發制定合適的規范) | 10 | 25 |
| Design | 具體設計 | 60 | 80 |
| Coding | 具體編碼 | 300 | 500 |
| Code Review | 代碼復審 | 20 | 20 |
| Test | 測試(自我測試,修改代碼,提交修改) | 60 | 100 |
| Reporting | 報告 | 45 | 70 |
| Test Repor | 測試報告 | 10 | 30 |
| Size Measurement | 計算工作量 | 15 | 15 |
| Postmortem & Process Improvement Plan | 事后總結,并提出過過程改進計劃 | 30 | 35 |
| 合計 | 1075 | 1785 |
浙公網安備 33010602011771號