wordcount编程
wordcount编程
https://github.com/hyanju/Project-Java
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/zswxy/computer-science-class4-2018 |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/computer-science-class4-2018/homework/11880 |
这个作业的目标 | 规范了写一个项目的流程 |
作业正文 | https://www.cnblogs.com/H-Alice/p/14596105.html |
其他参考文献 | Java菜鸟教程 |
psp表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 20 | 30 |
• Estimate | • 估计这个任务需要多少时间 | 1050 | 1050 |
Development | 开发 | 200 | 200 |
• Analysis | • 需求分析 (包括学习新技术) | 200 | 300 |
• Design Spec | • 生成设计文档 | 60 | 30 |
• Design Review | • 设计复审 | 30 | 30 |
• Coding Standard | • 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
• Design | • 具体设计 | 30 | 10 |
• Coding | • 具体编码 | 100 | 120 |
• Code Review | • 代码复审 | 100 | 60 |
• Test | • 测试(自我测试,修改代码,提交修改) | 100 | 100 |
Reporting | 报告 | 150 | 120 |
• Test Repor | • 测试报告 | 10 | 10 |
• Size Measurement | • 计算工作量 | 10 | 10 |
• Postmortem & Process Improvement Plan | • 事后总结, 并提出过程改进计划 | 30 | 20 |
合计 | 1050 | 1050 |
解题思路
字符统计思路:通过Ascii码值来限定字符
单词统计思路:通过分隔符进行分割,之后再通过正则表达式来筛选正确单词
行数统计思路:统计回车数
单词频率统计思路:HashMap存储键值对
代码规范链接
https://github.com/hyanju/Project-Java/blob/main/codestyle.md
设计与实现过程
一共有四个类,每个类中写有一个方法
核心代码
字符统计
while ((read = buff.read()) != -1) {
if(read>=32&&read<=126) { //统计字符数
charCount++;
}
}
行数统计
while (value != null) {
if(!"".equals(value)) {
i++;
}
value=in.readLine();
}
if (in!= null)
in.close();
单词统计(字符串分割+正则表达式+大写字母转小写)
//字符串分割
String[] str1 = str.split("\\s+");
// 按指定模式在字符串查找
String pattern = "^[a-zA-Z]{4}[a-zA-Z0-9]*$";
String pattern1 = "[a-zA-Z]{4}$";
//判断是否为小写字母
if(Character.isUpperCase(c)) {
sb.append(Character.toLowerCase(c));
}else {
sb.append(Character.toLowerCase(c));
}
单词频率显示
m=0;
ArrayList<String> list1 =new ArrayList<>();
ArrayList<String> list2 =new ArrayList<>();
max=num[0];
while(m<num.length) {
while(m<num.length) {
if(max==num[m]) {
list1.add(str2[m]);
m++;
}else {
max=num[m];
break;
}
}
//list1.sort(Comparator.);
Collections.sort(list1);
list2.addAll(list1);
list1.clear();
}
运行截图
性能改进
暂无
单元测试
通过在终端输出来测试的
System.out.println();
异常处理说明
系统找不到文件
心路历程及收获
心路历程:做起来感觉很繁琐
收获:对于开发流程有一定了解了