https://gitee.com/JeremyGilbert/wordcountgit
PSP2.1 | 我的開發流程 | 預估耗費時間(分鐘) | 實際耗費時間(分鐘) |
---|---|---|---|
Planning | 計劃 | 50 | 60 |
· Estimate | 明確需求和其餘相關因素,估計每一個階段的時間成本 | 50 | 60 |
Development | 開發 | 750 | 900 |
· Analysis | 需求分析 (包括學習新技術) | 100 | 150 |
· Design Spec | 生成設計文檔 | 60 | 60 |
· Design Review | 設計複審 | 40 | 30 |
· Coding Standard | 代碼規範 | 30 | 25 |
· Design | 具體設計 | 200 | 200 |
· Coding | 具體編碼 | 200 | 250 |
· Code Review | 代碼複審 | 30 | 20 |
· Test | 測試(自我測試,修改代碼,提交修改) | 70 | 180 |
Reporting | 報告 | 90 | 95 |
· | 測試報告 | 30 | 30 |
· | 計算工做量 | 20 | 20 |
· | 並提出過程改進計劃 | 40 | 45 |
(1)首先選擇了開發語言Java。
(2)而後就是由於要讀取文件中的內容,想到要用setter與getter方法,在getter方法以前,判斷文字,而後再輸出。github
int charCount; // 字符統計
int blankCount; // 空格統計
int tabCount; // 水平字符Count
int enterCount; // 換行符Count
int total; // 均算字符統計
int noCount; // 非字母數字統計
int lineCount; // 行數統計
int wordCount; // 單詞統計
int lineValidate; // 有效行數數組
採用String的方法來讀取文件函數
一、數組越界問題,改用用動態分配對象來儲存數據工具
二、有效行的邏輯有問題,想要用標誌位來進行判斷,這樣來統計有效行性能
public int getLineValidate() { //有效行數統計
String[] line = text.split("\n");
char c='\0';
boolean flag = true;
for(int i=0; i<line.length; i++){
for(int j=0; j<line[i].length(); j++){
c = line[i].charAt(j);
if(c ==' '){
flag = false;
}else{
flag = true;
break;
}
}
if(flag) lineValidate++;
flag = true;
}
return lineValidate;
}
public void setLineValidate(int lineValidate) {
this.lineValidate = lineValidate;
}
public wordcount(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getCharCount() {
return charCount;
}
public void setCharCount(int charCount) {
this.charCount = charCount;
}
public int getTabCount() {
return tabCount;
}
public void setTabCount(int tabCount) {
this.tabCount = tabCount;
}
public int getEnterCount() {
return enterCount;
}
public void setEnterCount(int enterCount) {
this.enterCount = enterCount;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getBlankCount() {
return blankCount;
}
public void setBlankCount(int blankCount) {
this.blankCount = blankCount;
}
public int getNoCount() {
return noCount;
}
public void setNoCount(int noCount) {
this.noCount = noCount;
}
public int getLineCount() {
return lineCount;
}
public void setLineCount(int lineCount) {
this.lineCount = lineCount;
}
public void setWordCount(int wordCount) {
this.wordCount = wordCount;
}學習
public void getCharacterCount() { //字符、空格、製表、換行統計
char c = '\0';
for (int i = 0; i < text.length(); i++) {
c = text.charAt(i);
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
charCount++;
} else if (c == ' ') {
blankCount++;
} else if (c == '\r') {
tabCount++;
} else if (c == '\n') {
enterCount++;
lineCount++;
}
}
total = charCount + blankCount + tabCount + enterCount;
}
public int getWordCount() { //單詞統計
char c = '\0';
int j = 0;
word[0] = "";
boolean flag = false;
for (int i = 0; i < text.length(); i++) {
c = text.charAt(i);
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
word[j] = word[j] + c;
flag = true;
} else if (flag == true) {
j++;
flag = false;
}
}
return j;
}
public void orderWord(){ //單詞頻數
String temp;
for(int i=0; i<word.length-1; i++){
for(int j=i; j<word.length; j++){
if(word[i].compareTo(word[j])>0){
temp = word[i];
word[i] = word[j];
word[j] = temp;
}
}
}測試
測試結果:this
在此次實驗中暴露出本身有不少地方的不懂,一開始沒有設計清楚,後邊花費了不少時間去修改。編碼