实现一个能够对文本文件中的单词的词频进行统计的控制台程序。
进行单元测试、回归测试、效能测试,在实现上述程序的过程中使用相关的工具。
进行个人软件过程(PSP)的实践,逐步记录自己在每个软件工程环节花费的时间。
使用源代码管理系统 (码云)。
博客作业要求地址:https://www.cnblogs.com/happyzm/p/9559372.html
码云地址:https://gitee.com/wengmingqiang/PersonalProject-C
PSP2.1 | ** 个人开发流程 ** | ** 预估耗费时间(分钟)** | 实际耗费时间(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 40 |
· Estimate | 明确需求和其他相关因素,估计每个阶段的时间成本 | 20 | 30 |
Development | 开发 | 700 | 500 |
· Analysis | 需求分析 (包括学习新技术) | 60 | 80 |
· Design Spec | 生成设计文档 | 80 | 60 |
· Design Review | 设计复审 | 30 | 15 |
· Coding Standard | 代码规范 | 30 | 15 |
· Design | 具体设计 | 100 | 80 |
· Coding | 具体编码 | 100 | 180 |
· Code Review | 代码复审 | 40 | 20 |
· Test | 测试(自我测试,修改代码,提交修改) | 60 | 180 |
Reporting | 报告 | 50 90 | |
· | 测试报告 | 40 | 30 |
· | 计算工作量 | 15 | 20 |
· | 并提出过程改进计划 | 10 | 20 |
拿到这个项目,大致的思路就是,把文件中的字符都读到一个String字符串中,再对字符串进行操作
统计Ascii码:计算string的字符串的长度
统计行数:对文件每行每行的读取,有读取出数据则 行数line++ ,最后返回line
统计单词数:把String函数用split函数对字符串进行划分,存入到一个String数组中,再计算数组的长度
统计单词频度:用键值对(key-value)映射,单词作为key,单词数量作为value。
//参数string为你的文件名*/
public static String readFileContent(String fileName) throws IOException {
File file = new File(fileName);
BufferedReader bf = new BufferedReader(new FileReader(file));
String content = "";
StringBuilder sb = new StringBuilder();
while(content != null){
content = bf.readLine();
if(content == null){
break;
}
sb.append(content.trim());
}
bf.close();
return sb.toString();
}
原文:https://www.cnblogs.com/wengmq/p/9641300.html