编程作业
这个作业属于哪个课程 | https://edu.cnblogs.com/campus/zswxy/computer-science-class4-2018/ |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/computer-science-class4-2018/homework/11880 |
这个作业的目标 | <能够实现统计文本文档词频的控制台程序,进行代码优化,完成代码完成词频统计个人作业,实现要求。> |
参考文献 | 《构建之法》、《现代软件工程》、CSDN、博客园、Git |
码云链接 https://gitee.com/wuming67/project-java/tree/master/20188510
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 15 | 20 |
• Estimate | • 估计这个任务需要多少时间 | 15 | 20 |
Development | 开发 | 500 | 760 |
• Analysis | • 需求分析 (包括学习新技术) | 40 | 60 |
• Design Spec | • 生成设计文档 | 20 | 20 |
• Design Review | • 设计复审 | 10 | 15 |
• Coding Standard | • 代码规范 (为目前的开发制定合适的规范) | 20 | 25 |
• Design | • 具体设计 | 20 | 20 |
• Coding | • 具体编码 | 200 | 220 |
• Code Review | • 代码复审 | 30 | 30 |
• Test | • 测试(自我测试,修改代码,提交修改) | 60 | 70 |
Reporting | 报告 | 70 | 90 |
• Test Repor | • 测试报告 | 45 | 60 |
• Size Measurement | • 计算工作量 | 10 | 10 |
• Postmortem & Process Improvement Plan | • 事后总结, 并提出过程改进计划 | 15 | 20 |
合计 | 485 | 1200 | 1500 |
代码规范 https://gitee.com/wuming67/project-java/blob/master/20188510/codestyle.md
选择编程语言
- Java语言
对于题目的理解与知识点的使用
- 本题的思想是想用文本文件来进行统计
- 第二就是对各种字符的统计,不管大小写、单词都要进行统计,然后输出,这里用到的知识点就是对字符串的判断
- 题目想要分类输出,当然这里必须要把单词,行数等分开来统计,即分类统计
开始设计和编码
- 进行类的划分
- 进行编码
遇到问题的解决方法
- 上网找资料解答疑惑,还有就是问同学,在微信群里和老师同学交流
代码说明
1、WordC()方法,用来用于统计字符的数量
public class WordC
private int wordnumber=0;
private int charnumber=0;
private int line=0;
String text;
public WordC(String text) {
this.text = text;
}
public int getWordnumber() {
String str=text;
String[] words=str.split("\\s*[^0-9a-zA-Z]+");
for(String s:words) {
if(s.matches("[a-zA-Z]{4,}[a-zA-Z0-9]*")) {
wordnumber++;
}
}
return wordnumber;
}
public int getCharnumber() {
for(int i=0;i<text.length();i++) {
char c=text.charAt(i);
if(c > 31 && c < 127 ||c == 10) {
charnumber++;
}
}
return charnumber;
}
public int getLine() {
String[] lines=text.split("\r\n");
for(int i=0;i<lines.length;i++) {
if(lines[i].trim().length()!=0) {
line++;
}
}
return line;
}
2、File_read()方法,用来读取文本文档
public class File_read {
public String readToString(String filepath) throws IOException {
File file =new File(filepath);
FileInputStream files=new FileInputStream(file);
Long filelength =file.length();
byte[] by =new byte[filelength.intValue()];
StringBuffer buf = new StringBuffer();
if(file.isFile()&&file.exists()) {
if(files.read(by)!=-1) {
buf.append(new String(by));
}
}files.close();
return buf.toString();
心路历程与收获
这次的个人项目真的是个挑战,才打开博客的时候什么都看不懂,琢磨了半天都不知道从哪入手,对于我这种编程能力不强的人来说,编程能力的提高是迫在眉睫的了。这次的代码也有一部分是借鉴了室友和同学的,然后才写了自己的代码,还问了他们好多问题,但这次的作业也有一些没有完成,那些没完成的希望在之后学会了再来继续完成。