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 ...
随机推荐
- HBuilder 做移动端app流程
1.新建一个移动项目 2.编写代码 3.发行-发行为原生安装包,配置参数 选择icon 和引导页
- uvm_reg_file——寄存器模型(十四)
有了uvm_reg_field, uvm_reg, uvm_block, 也许我们需要跟大的uvm_file,这就是传说中的寄存器堆. // // CLASS: uvm_reg_file // Reg ...
- node执行cmd命令方法
var cmd='tasklist';//获取 子进程模块的exec方法,用于执行cmd命令var exec = require('child_process').exec; //运行 定义的cmd命 ...
- ACM的数学基础
懒得整理了,请勿往下看. (一)欧拉函数 设n为正整数,以φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值,这里函数φ:N→N,n→φ(n)称为欧拉函数.有如下一些性质: (1)欧拉 ...
- GWTDesigner_v5.1.0破解码
GWTDesigner_v5.1.0_win32_x86.exe破解码,双击运行keygeno.jar,然后输入用户名.网卡MAC,然后单击Generate,将生成的文件放在C:\Documents ...
- Java中的集合Collection接口
/* 集合:集合是存储对象数据的集合容器.集合比数组的优势: 1. 集合可以存储任意类型的对象数据,数组只能存储同一种数据类型 的数据. 2. 集合的长度是会发生变化的,数组的长度是固定的.----- ...
- Silverlight日记:动态操作Grid
一,动态生成Grid public static Grid CreateGrid(List<T_METER> List) { var g = new Grid(); if (null == ...
- win10中打开SQL Server 2008 的SQL Server配置管理器方法
win10找不到SQL Server配置管理器 搜索 SQLServerManager10.msc,或者运行文件:“C:\Windows\SysWOW64\SQLServerManager10.msc ...
- LLDB详解
LLDB的Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.平时用Xcode运行程序,实际走的都是LLDB.熟练使用LLDB,可以让你debug事半功倍 L ...
- Mysql中反引号和单引号的区别
反引号,一般在ESC键的下方. 它是为了区分MYSQL的保留字与普通字符而引入的符号.举个例子:SELECT `select` FROM `test` WHERE select='字段值'在test表 ...