一、GitHub地址
https://github.com/JasonLiu1105/WordCount
二、PSP表格
PSP2.1 |
PSP阶段 |
预估耗时 (分钟) |
实际耗时 (分钟) |
Planning |
计划 |
20 |
20 |
· Estimate |
· 估计这个任务需要多少时间 |
2days |
3days |
Development |
开发 |
1day |
1day |
· Analysis |
· 需求分析 (包括学习新技术) |
240 |
240 |
· Design Spec |
· 生成设计文档 |
20 |
20 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
-- |
-- |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
-- |
-- |
· Design |
· 具体设计 |
60 |
60 |
· Coding |
· 具体编码 |
1 |
2 |
· Code Review |
· 代码复审 |
180 |
180 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
120 |
120 |
Reporting |
报告 |
30 |
60 |
· Test Report |
· 测试报告 |
60 |
120 |
· Size Measurement |
· 计算工作量 |
30 |
20 |
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
30 |
60 |
合计 |
2days |
3days |
三、解题思路
1.拿到题目以后,先选择一个合适的语言进行编写
2.根据题目中所给的基本功能,先着手将基本功能实现,再进行相应的扩展功能
3.对于程序中可能会用到的java的知识点,要提前进行了解
4.上网查找跟题目要求功能有相似的java 程序,很好的了解明白后,再根据题目进行开发
四、程序设计实现过程
本程序使用了一个类WordCountX,然后将各种相关方法写入(在代码开发的过程中发现只写到一个类里会让代码过于复杂,当后期对程序进行修改的时候比较费力)。通过主函数中调用各方法实现要求功能
五、代码说明
主函数
public class WordCountX { public static void main(String[] args){ // String inPath = "/Users/jason/Desktop/1.txt"; //文件名 String outPath="result.txt"; //输出文件名,默认为result.txt int line=0; int num=0; int letter=0; int space=0; int word=0; boolean c = false; boolean w = false; boolean l = false; boolean o = false; boolean a = false; boolean e = false; boolean s =false; String inPath=null; String stopPath=null;
/**
* 统计数字数
* @param str
* @return
*/
public static int countNumber(String str)
/**
* 统计字母数
* @param str
* @return
*/
public static int countLetter(String str)
/**
* 统计汉字数
* @param str
* @return
*/
public static int countChinese(String str)
/**
*统计不同类别行数
*@return int[]//代码,空白,注释
* @param
*/
public static long[] coutDiff(String line)
/**
* 统计空格数
* @param str
* @return
*/
public static int countSpace(String str)
/**
*包含stopLists
*@param
*@return int
*/
static int countStopWords( BufferedReader thefile,String txt)
/**
*输出到文件
*@param str,path
*@return
*/
public static void printToFile(String filepath,String str)
六、测试设计过程
1、未能写出测试脚本,而是在Terminal进行测试,共产生如下10个测试用例。
在终端中进行测试
(注意:每次进行“-c或-w或-l的操作时所有结果都会输出在终端里,只是在result.test里分别显示”)
Last login: Tue Mar 20 16:03:01 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -c -w -l
/Users/jason/Desktop/1.txt, 行数:49 /Users/jason/Desktop/1.txt, 字符数:2004 /Users/jason/Desktop/1.txt, 单词数:9
Last login: Tue Mar 20 16:03:01 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -c -w
Last login: Tue Mar 20 16:03:01 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -w -l
Last login: Tue Mar 20 16:03:01 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -w -l 数字数:282
Last login: Tue Mar 20 16:03:01 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -c -l 数字数:282
MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -c
/Users/jason/Desktop/1.txt, 字符数:2004
MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -w
/Users/jason/Desktop/1.txt, 单词数:9
MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -l
/Users/jason/Desktop/1.txt, 行数:49
Last login: Tue Mar 20 16:54:05 on ttys001 MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/IdeaProjects/WordCountX/out/artifacts/WordCountX_jar2/WordCountX.jar -c -l -a -w -o /Users/jason/Desktop/21.txt /Users/jason/Desktop/1.txt
/Users/jason/Desktop/1.txt, 代码/空白/注释:48/1/0
MrniudeMacBook-Pro:~ jason$ java -jar /Users/jason/Documents/GitHub/WordCount/out/artifacts/WordCountX_jar2/WordCountX.jar /Users/jason/Desktop/1.txt -e stopList.txt // 停用词表,统计文件单词总数时,不统计该表中的单词
七、参考文献链接
http://blog.csdn.net/u013177799/article/details/76062976
https://www.cnblogs.com/wangcp-2014/p/5851986.html
http://blog.csdn.net/u010137431/article/details/46823293
https://stackoverflow.com/questions/4330936/how-can-i-convert-a-jar-to-an-exe
八、作业改进
还有唯一的附加功能-s没有及时实现,但由于时间原因,必须今晚提交博客,所以会在后期抓
原文地址:https://www.cnblogs.com/liutzh1105/p/8611414.html