https://gitee.com/WoShiLiangChaoWeiDeShiYou/PersonalProject-Java/tree/master/wordcountjavascript
PSP2.1 | 我的开发流程 | 预估耗费时间(分钟) | 实际耗费时间(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 50 |
· Estimate | 明确需求和其余相关因素,估计每一个阶段的时间成本 | 30 | 60 |
Development | 开发 | 100 | 300 |
· Analysis | 需求分析 (包括学习新技术) | 50 | 100 |
· Design Spec | 生成设计文档 | 60 | 80 |
· Design Review | 设计复审 | 40 | 50 |
· Coding Standard | 代码规范 | 40 | 60 |
· Design | 具体设计 | 60 | 150 |
· Coding | 具体编码 | 20 | 60 |
· Code Review | 代码复审 | 30 | 0 |
· Test | 测试(自我测试,修改代码,提交修改) | 0 | 0 |
Reporting | 报告 | 20 | 0 |
· | 测试报告 | 15 | 0 |
· | 计算工做量 | 30 | 0 |
· | 并提出过程改进计划 | 0 | 0 |
一、本题我选用的编程语言是Java
二、要统计txt文件中单词数目,就要对txt文件的内容进行读取,使用流,就写了一个;须要对读取的数据内容进行判别分析,单词、空格、字符、数字等; 对于重复出现的单词进行统计次数;无论大小写仍是单词等都要进行统计,最后对每种字符进行分类和统计输出;这就用到了Java语言对字符串判断的知识点和分类统计的知识点
三、对于编码的设计,我先对类进行了划分,而后才开始编码,我的以为这样比较有效率
四、还有一点就是遇到问题时怎么解决,遇到的问题大部分都是上百度查了而后本身理解以后进行尝试,尝试了不少不少遍最终仍是成功了,说明坚持就是胜利!java
一、划分的类:git
import java.util.Map; public class Word{ private int wordnumber=0; private int charnumber=0; private int line=0; private Map<String,Integer> wordcount; String text; public Word(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; } public Map getWordcount() {//统计每一个单词出现次数 String []wordnum=text.split("\\s"); for(int i=0;i<wordnum.length;i++) { if(wordnum[i].length()>=4) { char c; for (int j = 0; j < 4; j++) { c = wordnum[i].charAt(j); if (!(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')) { if(wordcount.get(wordnum[i]) != null) { wordcount.put(wordnum[i], wordcount.get(wordnum[i])+1); } else { wordcount.put(wordnum[i], 1); } } } } } return wordcount; } }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class File_rw { 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(); } }
我的项目的难度确实有些大,本身要作一个完美的项目更是难上加难,思考了好久才开始着手写代码,而且实现的功能还十分简陋。好比对于字符单词处理若是使用正则表达式。因为本身以前没有好好学习,如今才以为书到用时方恨少的感受。不少代码包括一些基础简单的都要上网查资料或者咨询同窗。本身以后会更认真更努力去完善本身的不足,争取进步正则表达式