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
在此次实验中暴露出本身有不少地方的不懂,一开始没有设计清楚,后边花费了不少时间去修改。编码