WordCount 2.0(结对项目)
序言
合作伙伴
201631062220 201631062120
项目码云地址:
https://gitee.com/zhege/WordCount
作业详细要求
正文
1.概述
该项目的PSP表格如下

2.互审代码
李欣 TO 王筱哲 :逻辑写的非常不错,唯一不足的是注释有点少,希望以后多写注释
王筱哲 TO 李欣 :思路很清楚,感觉还不错
基本功能基本一样,扩展功能主要是分成几个class,都有点困扰,代码不是那么清楚,都有所改动,最后基本一致
3.程序设计实现过程
1.结构图

2.UML类图

3.属性方法
属性
public int chars;
public int words;
public int lines;
public int codeLines; //代码行数
public int empLines; //空行数
public int comLines; //注释行数 public int getChars() {
return chars;
} public int getWords() {
return words;
} public int getLines() {
return lines;
} public int getCodeLines() {
return codeLines;
} public int getEmpLines() {
return empLines;
} public int getComLines() {
return comLines;
}
WC
public static String inputFile;
public static String outputFile;
public static boolean needC;
public static boolean needW;
public static boolean needL;
public static boolean needO;
public static boolean needS; //输入参数中是否有“-s”
public static boolean needA; //输入参数中是否有“-a”
public static boolean needE; //输入参数中是否有“-e”
Main
方法
//实现参数的选择
package wc; import java.io.*;
import java.util.ArrayList; public class Main {
public static String inputFile;
public static String outputFile;
public static boolean needC;
public static boolean needW;
public static boolean needL;
public static boolean needO;
public static boolean needS; //输入参数中是否有“-s”
public static boolean needA; //输入参数中是否有“-a”
public static boolean needE; //输入参数中是否有“-e” public static void main(String[] args) {
inputFile = "";
StopList.stopList="";
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
if ("-c".equals(args[i])) {
needC = true;
} else if ("-w".equals(args[i])) {
needW = true;
} else if ("-l".equals(args[i])) {
needL = true;
} else if ("-s".equals(args[i])) {
needS = true;
} else if ("-a".equals(args[i])) {
needA = true;
} else if ("-e".equals(args[i])) {
needE = true;
StopList.stopList = args[i + 1];
} else if ("-o".equals(args[i])) {
needO = true;
outputFile = args[i + 1];
} else {
if (!args[i - 1].equals("-e") && !args[i - 1].equals("-o")) { inputFile = args[i];
}
} }
String outputStr = "";
ArrayList<String> fileNames = new ArrayList<String>();
if (!needS) {
fileNames.add(inputFile);
} else {
S.s(fileNames);
}
int len = fileNames.size();
String fn; for (int i = 0; i < len; i++) {
fn = fileNames.get(i);
System.out.println(fn);
String fileShortName = fn.substring(fn.lastIndexOf("\\") + 1, fn.length());
Wc wc;
if (needC || needW || needL) {
//统计基本信息
if (needE) {
wc=BasicInfoWithSL.getBasicInfoWithSL(fn,StopList.stopList);
} else {
wc=BasicInfo.basicInfo(fn);
} if (needC) { outputStr += fileShortName;
outputStr += ", 字符数: ";
outputStr += wc.getChars();
outputStr += "\r\n";
}
if (needW) { outputStr += fileShortName;
outputStr += ", 单词数: ";
outputStr += wc.getWords();
outputStr += "\r\n";
}
if (needL) { outputStr += fileShortName;
outputStr += ", 行数: ";
outputStr += wc.getLines();
outputStr += "\r\n";
}
}
if (needA) {
wc = ComInfo.comInfo(fn);//统计复杂信息
//file1.c, 代码行/空行/注释行: 5/2/3
outputStr += fileShortName;
outputStr += ", 代码行/空行/注释行: ";
outputStr += wc.codeLines;
outputStr += "/";
outputStr += wc.empLines;
outputStr += "/";
outputStr += wc.comLines;
outputStr += "\r\n";
} } System.out.println(outputStr);
if (!needO) {
outputFile = "result.txt";
}
try { File writename = new File(outputFile);
writename.createNewFile();
BufferedWriter out = new BufferedWriter(new FileWriter(writename));
out.write(outputStr);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
} } }
Main方法
//基本功能的实现
package wc; import java.io.*;
/**
* Author: wuhen
* Date: 2018/9/20
* Time: 18:35
*/
public class BasicInfo {
public static Wc basicInfo(String fileName)
{
Wc wc=new Wc();
char charNow;
try
{
File filename = new File(fileName);
InputStreamReader reader = new InputStreamReader(
new FileInputStream(filename));
BufferedReader br = new BufferedReader(reader);
String line ;
line = br.readLine();
boolean partition=true;
while (line != null)
{ wc.chars+=line.length();
wc.lines++; for(int i=0;i<line.length();i++)
{
charNow=line.charAt(i);
if(partition==true&&charNow!='/'&&charNow!='*'&&charNow!='{'&&charNow!='}'&&charNow!='c'&&charNow!='('&&charNow!=')'&&charNow!='\t'&&charNow!=','&&charNow!='.'&&charNow!='?')
{
wc.words++;
}
if(charNow==' '||charNow=='\t'||charNow==','||charNow==',')
{
partition=true;
} }
line = br.readLine();
}
wc.chars+=wc.lines-1;
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return wc;
}
}
基本功能统计
//扩展功能的实现(停用表) 递归的调用
package wc; import java.io.*;
/**
* Author: wuhen
* Date: 2018/9/20
* Time: 18:35
*/
public class BasicInfo {
public static Wc basicInfo(String fileName)
{
Wc wc=new Wc();
char charNow;
try
{
File filename = new File(fileName);
InputStreamReader reader = new InputStreamReader(
new FileInputStream(filename));
BufferedReader br = new BufferedReader(reader);
String line ;
line = br.readLine();
boolean partition=true;
while (line != null)
{ wc.chars+=line.length();
wc.lines++; for(int i=0;i<line.length();i++)
{
charNow=line.charAt(i);
if(partition==true&&charNow!='/'&&charNow!='*'&&charNow!='{'&&charNow!='}'&&charNow!='c'&&charNow!='('&&charNow!=')'&&charNow!='\t'&&charNow!=','&&charNow!='.'&&charNow!='?')
{
wc.words++;
}
if(charNow==' '||charNow=='\t'||charNow==','||charNow==',')
{
partition=true;
} }
line = br.readLine();
}
wc.chars+=wc.lines-1;
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return wc;
}
}
扩展功能
package wc; import java.io.*;
import java.util.ArrayList; /**
* Author: wuhen
* Date: 2018/10/16
* Time: 9:22
*/
public class StopList {
public static String stopList;
//停用词表
public static void getStopList(ArrayList<String> wordsIgnored)
{ try
{ // 防止文件建立或读取失败,用catch捕捉错误并打印,也可以throw /* 读入stopList */
File filename = new File(stopList); // 要读取以上路径的input。txt文件
InputStreamReader reader = new InputStreamReader(
new FileInputStream(filename)); // 建立一个输入流对象reader
BufferedReader br = new BufferedReader(reader); // 建立一个对象,它把文件内容转成计算机能读懂的语言
String line ;
line = br.readLine(); String reg1 = " +";
while (line != null)
{
//将读取的行分割成各个单词
String str[] = line.split(reg1); for(int i=0;i<str.length;i++)
{
wordsIgnored.add(str[i]); //将停用词表中的单词放入数组wordsIgnored
}
line = br.readLine(); // 一次读入一行数据
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
} }
}
stopList
//高级功能,只做了个界面,基本没有实现(时间有限)
//利用了javaFx

//ui,fxml代码(一些简单设计)
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml"
fx:controller="sample.Controller">
<children>
<CheckBox fx:id="isCountLine" layoutX="97.0" layoutY="49.0" mnemonicParsing="false" selected="false"
text="行数统计"/>
<CheckBox fx:id="isCountChar" layoutX="213.0" layoutY="48.0" mnemonicParsing="false" text="字符统计"/>
<CheckBox fx:id="isCountWord" layoutX="97.0" layoutY="111.0" mnemonicParsing="false" text="单词统计"/>
<CheckBox fx:id="countCodeInfo" layoutX="213.0" layoutY="111.0" mnemonicParsing="false" text="代码行\注释行\空行"/>
<CheckBox fx:id="isRecursion" layoutX="360.0" layoutY="48.0" mnemonicParsing="false" onAction="#changeTextState"
text="递归处理"/>
<Button layoutX="409.0" layoutY="271.0" minHeight="15.999908447265625" mnemonicParsing="false" onAction="#textProcess"
prefHeight="27.0" prefWidth="76.0" text="执行" textAlignment="LEFT"/>
<TextField fx:id="regexField" editable="false" layoutX="447.0" layoutY="44.0" onMouseClicked="#isCheckRecursion"
prefHeight="27.0" prefWidth="108.0" promptText="过滤条件"/>
<TextField fx:id="resultFile" layoutX="176.0" layoutY="273.0" prefHeight="27.0" prefWidth="200.0"
promptText="结果文件(默认result.txt)"/>
<Label layoutX="103.0" layoutY="277.0" text="结果文件:">
<font>
<Font size="14.0" fx:id="x1"/>
</font>
</Label>
<Label font="$x1" layoutX="89.0" layoutY="170.0" text="停止词文件:"/>
<Label ellipsisString="" font="$x1" layoutX="61.0" layoutY="224.0" text="输入文件或目录:" textAlignment="LEFT"
textOverrun="ELLIPSIS" underline="false"/>
<TextField fx:id="stopFile" layoutX="176.0" layoutY="166.0" onMouseClicked="#chooseStopFile" prefHeight="27.0"
prefWidth="200.0" promptText=""/>
<TextField id="stopFile" fx:id="inputFile" layoutX="176.0" layoutY="220.0" onMouseClicked="#chooseInput"
prefHeight="27.0" prefWidth="200.0" promptText=""/>
</children>
</AnchorPane>
ui.fxml
4.测试
1.测试脚本


2.测试效果



3.测试评价
时间有限,高级功能没有实现,但是扩展功能的实现还是可以的,设计到的东西有很多,但是经过研究测试后效果还是不错的。以后有时间继续完成
WordCount 2.0(结对项目)的更多相关文章
- WordCount结对项目
合作者:201631062124,201631062423 代码地址:https://gitee.com/yryx/WordCount 作业地址:https://edu.cnblogs.com/cam ...
- 系统分析与设计结对项目——WordCount
结对项目完成WordCount 合作者:201631062507 201631062526(学号) 代码地址:https://gitee.com/WordCountMC/WordCountTeam ...
- 复利计算--结对项目<04-11-2016> 1.0.0 lastest 阶段性完工~
结对项目:Web复利计算 搭档博客地址:25江志彬 http://www.cnblogs.com/qazwsxedcrfv/ 个人摘要: (2016-04-09-12:00)补充:之前传送门没做好, ...
- 软工结对项目之词频统计update
队友 胡展瑞 031602215 作业页面 GitHub 具体分工 111500206 赵畅:负责WordCount的升级,添加新的命令行参数支持(自定义输入输出文件,权重词频统计,词组统计等所有新功 ...
- 高级四则运算器—结对项目反思(193 & 105)
高级四则运算器—结对项目反思(193 & 105) 本周我和一位韩国同学(71061105)一起结对编程完成了我们的结对项目——高级的小学四则运算题目生成器. PSP表格 PSP2.1 P ...
- 高级四则运算器—结对项目总结(193 &105)
高级四则运算器—结对项目总结 为了将感想与项目经验体会分割一下,特在此新开一篇博文. 界面设计 啥都不说,先上图震慑一下... 上面的三个界面是我们本次结对项目的主界面,恩,我也觉得挺漂亮的!你问我界 ...
- 高级软件工程2017第3次作业——结对项目:四则运算题目生成程序(基于GUI)
Deadline:2017-10-11(周三)21:00pm (注:以下内容参考集大作业 ) 前言 想过和别人一起探索世界吗?多么希望,遇到困难时,有人能一起探讨:想要懈怠时,有人推你一把:当你专注于 ...
- 2018-2019-2 《Java程序设计》结对项目阶段总结《四则运算——整数》(二)
20175218 2018-2019-2 <Java程序设计>结对项目阶段总结<四则运算--整数> 一.需求分析 实现一个命令行程序,要求: 自动生成小学四则运算题目(加,减, ...
- 结对项目——四则运算GUI项目
一.项目地址:https://git.coding.net/lvgx/wsz.git 二.PSP: PSP2.1 任务内容 计划共完成需要的时间(min) 实际完成需要的时间(min) Plannin ...
随机推荐
- PC端和手机端页面的一丢丢区别
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- 文件系统结构-《循序渐进linux》
1.目录结构 很多linux的发行版都遵循FSSTND标准,这一标准仅包含系统最基本的文件. /dev 设备文件 /bin 可执行的二进制文件 /opt /root 超级用户的主目录 /home 每个 ...
- Jquery 事件 DOM操作
常规事件: 把JS的事件 on去掉即可 例如:js document.getElementById("id").onclinck=function(){} Jquery ...
- ABAP vs Java, 蛙泳 vs 自由泳
去年7月定下的一年之内学会自由泳的目标终于实现了,特来还愿. ABAP和Java, 蛙泳和自由泳.前面的组合是Jerry用来挣钱养家的技术,后者是Jerry花了大量业余时间和金钱苦练的技能.或许有的朋 ...
- 多目标检测分类 RCNN到Mask R-CNN
最近做目标检测需要用到Mask R-CNN,之前研究过CNN,R-CNN:通过论文的阅读以及下边三篇博客大概弄懂了Mask R-CNN神经网络.想要改进还得努力啊... 目标检测的经典网络结构,顺序大 ...
- 11gR2 如何诊断节点重启问题
本文对如何诊断11gR2 GI环境下的节点重启问题进行了一些介绍. 首先,像10g版本一样,我们首先介绍在GI中能够导致节点重启的进程.1.Ocssd.bin:这个进程的功能和10g版本的功能基本差不 ...
- java,编写一个从1循环到150并在每行打印一个值,另外在每个3的倍数行上打印出foo,在每个5的倍数行上打印biz,在每个7的倍数上打印baz.
需求:编写一个从1循环到150并在每行打印一个值,另外在每个3的倍数行上打印出foo,在每个5的倍数行上打印biz,在每个7的倍数上打印baz. package study01; public cla ...
- cocos2dx 使用XMLHttpRequest时回调status为0的问题
今天使用cocos连接http访问时,使用XMLHttpRequest在pc上反问时正常的返回了status=0,但是在android上去返回status是0,看了一下底层代码, 发现status只有 ...
- mysql关联查询
mysql数据库的统计------生成统计信息 1.distinct:在一组之中将各个唯一的值找出来,如找出所有的品牌种类 mysql>select distinct brand_kind fr ...
- CodeForce:16C-Monitor
传送门:http://codeforces.com/problemset/problem/16/C Monitor time limit per test0.5 second memory limit ...