软件工程作业2

1.git地址:

 https://gitee.com/JeremyGilbert/wordcount

2.PSP表格

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

3.解题思路描述:

(1)首先选择了开发语言Java。
(2)然后就是因为要读取文件中的内容,想到要用setter与getter方法,在getter方法之前,判断文字,然后再输出。

4.设计实现过程:

int charCount; // 字符统计
int blankCount; // 空格统计
int tabCount; // 水平字符Count
int enterCount; // 换行符Count
int total; // 均算字符统计
int noCount; // 非字母数字统计
int lineCount; // 行数统计
int wordCount; // 单词统计
int lineValidate; // 有效行数

采用String的方法来读取文件

5.记录在改进程序性能上所花费的时间,描述你改进的思路

1、数组越界问题,改用用动态分配对象来储存数据

2、有效行的逻辑有问题,想要用标志位来进行判断,这样来统计有效行

6.代码说明,展示出项目关键代码,并解释思路与注释说明。

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;
}
}
}

 

测试结果:

 

7.结合在构建之法中学习到的相关内容与结对项目的实践经历,撰写解决项目的心路历程与收获。

在这次实验中暴露出自己有很多地方的不懂,一开始没有设计清楚,后边花费了很多时间去修改。

posted @ 2018-09-17 13:20  JeremyGilbert  阅读(209)  评论(3编辑  收藏  举报