软工作业-wc(java实现)
WC(源程序特征统计程序)
githud地址:https://github.com/705393356/wc.git
一、PSP表-预估耗时
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) |
---|---|---|
Planning | 计划 | 60 |
· Estimate | · 估计这个任务需要多少时间 | 60 |
Development | 开发 | 560 |
· Analysis | · 需求分析 (包括学习新技术) | 10 |
· Design Spec | · 生成设计文档 | 30 |
· Design Review | · 设计复审 (和同事审核设计文档) | 30 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 |
· Design | · 具体设计 | 30 |
· Coding | · 具体编码 | 360 |
· Code Review | · 代码复审 | 30 |
· Test | · 测试(自我测试,修改代码,提交修改) | 60 |
Reporting | 报告 | 100 |
· Test Report | · 测试报告 | 60 |
· Size Measurement | · 计算工作量 | 10 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 30 |
合计 | 720 |
二、解题思路
- 拿到这个题目后,因为平时常用的语言是java,所以决定用java来编写。因为java较少用到命令行界面,所以选择制作UI界面。
- 字符数量方面采用字符串检测的方式,而行数与单词数因为java具有逐行去除的方法,检测行的类型更为方便。
- java在io方面平时接触较少,所以专门去查了有关于javaAPI文档的io部分。
- 在做图形化页面时,选择文件界面的监听没有接触过,所以在网上查了许多博客。
三、设计实现过程
- 分为三个包:service(服务包),model(实体包),ui(界面包)
- model中为一个实体类CodeFile包含了要求的各个属性,service包中一个类包含了四个方法,ui包就 是图形界面的类
以下为设计流程图:
四、代码说明
//计算代码行数
public static CodeFile getLines(String filelocation) throws Exception{
CodeFile codeFile = new CodeFile();
String str="";
int WordsNum = 0;
File file=new File(filelocation);
if(file.exists()){
if(!(file.getName()).endsWith(".java")){
codeFile.setFlag(-1);
return codeFile;
}
FileInputStream input=new FileInputStream(file);
@SuppressWarnings("resource")
BufferedReader reader=new BufferedReader(new InputStreamReader(input));
while((str=reader.readLine())!=null){
//判断几种行数
if(str.trim().length()<1||str.trim().startsWith("{")||str.trim().startsWith("}")){
//判断空行
codeFile.setNullLines(codeFile.getNullLines()+1);
}else if(!(str.trim().startsWith("/*")||str.trim().startsWith("\\*")||str.trim().startsWith("*/")||str.trim().startsWith("//")||str.trim().startsWith("*"))){
//判断代码行
codeFile.setCodeLines(codeFile.getCodeLines()+1);
String str2 = str.trim();
System.out.println(str2);
//在代码行计算单词数
int newNum = DetermineWord(str2);
System.out.println("---------------" + newNum);
WordsNum +=newNum;
}
//余下注释
else {
codeFile.setAnnotations(codeFile.getAnnotations()+1);
}
}
codeFile.setWordNum(WordsNum);
codeFile.setTotalLines();
}else {
codeFile.setFlag(1);
return codeFile;
}
codeFile.setFlag(1);
return codeFile;
}
//判断字符串中单词数量,包含了去符号化
public static int DetermineWord(String str){
int num = 0;
char[] c = str.toCharArray();
int flag = 0;
for(int i=0;i<c.length;i++){
if(Character.isLetterOrDigit(c[i])&&flag==0){
flag = 1;
}else if(Character.isLetterOrDigit(c[i])&&flag==1){
continue;
}else if(!Character.isLetterOrDigit(c[i])&&flag==1){
num++;
flag=0;
continue;
}
}
System.out.println(num);
return num;
}
五、测试运行
运行界面:
选择界面:
可单选文件也可所选文件,这里展示多选文件
点击“计算行数与单词数”与“计算字符数”
六、PSP表-实际耗时
| PSP2.1 | Personal Software Process Stages | 实际耗时(分钟) |
|-----------------------------------------|-----------------------------------------|------------------|------------------|
| Planning | 计划 | 45 |
| · Estimate | · 估计这个任务需要多少时间 | 45 |
| Development | 开发 | 645 |
| · Analysis | · 需求分析 (包括学习新技术) | 15 |
| · Design Spec | · 生成设计文档 | 25 |
| · Design Review | · 设计复审 (和同事审核设计文档) | 30 |
| · Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 5 |
| · Design | · 具体设计 | 30 |
| · Coding | · 具体编码 | 420 |
| · Code Review | · 代码复审 | 40 |
| · Test | · 测试(自我测试,修改代码,提交修改) | 80 |
| Reporting | 报告 | 80 |
| · Test Report | · 测试报告 | 50 |
| · Size Measurement | · 计算工作量 | 10 |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 20 |
| 合计 | | 770 |
七、总结
- 遇到的困难
- 几乎没做过Java的UI界面,所以需要网上查找资料。最终使用了Java的Swing来完成。
- 在做检查单词数时设计了一些算法,但结果都不正确。问同学才纠正了思路不采用去符号的方式来检测。
- 对程序不满意的地方
- 为完成对文件夹的遍历而只是做了多选文件检测的功能。
- 收获
- 较深入的了解了java的UI设计
- 了解了项目开发的流程