序言

合作伙伴

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(结对项目)的更多相关文章

  1. WordCount结对项目

    合作者:201631062124,201631062423 代码地址:https://gitee.com/yryx/WordCount 作业地址:https://edu.cnblogs.com/cam ...

  2. 系统分析与设计结对项目——WordCount

    结对项目完成WordCount 合作者:201631062507  201631062526(学号) 代码地址:https://gitee.com/WordCountMC/WordCountTeam ...

  3. 复利计算--结对项目<04-11-2016> 1.0.0 lastest 阶段性完工~

    结对项目:Web复利计算 搭档博客地址:25江志彬  http://www.cnblogs.com/qazwsxedcrfv/ 个人摘要: (2016-04-09-12:00)补充:之前传送门没做好, ...

  4. 软工结对项目之词频统计update

    队友 胡展瑞 031602215 作业页面 GitHub 具体分工 111500206 赵畅:负责WordCount的升级,添加新的命令行参数支持(自定义输入输出文件,权重词频统计,词组统计等所有新功 ...

  5. 高级四则运算器—结对项目反思(193 & 105)

    高级四则运算器—结对项目反思(193 & 105) 本周我和一位韩国同学(71061105)一起结对编程完成了我们的结对项目——高级的小学四则运算题目生成器. PSP表格   PSP2.1 P ...

  6. 高级四则运算器—结对项目总结(193 &105)

    高级四则运算器—结对项目总结 为了将感想与项目经验体会分割一下,特在此新开一篇博文. 界面设计 啥都不说,先上图震慑一下... 上面的三个界面是我们本次结对项目的主界面,恩,我也觉得挺漂亮的!你问我界 ...

  7. 高级软件工程2017第3次作业——结对项目:四则运算题目生成程序(基于GUI)

    Deadline:2017-10-11(周三)21:00pm (注:以下内容参考集大作业 ) 前言 想过和别人一起探索世界吗?多么希望,遇到困难时,有人能一起探讨:想要懈怠时,有人推你一把:当你专注于 ...

  8. 2018-2019-2 《Java程序设计》结对项目阶段总结《四则运算——整数》(二)

    20175218 2018-2019-2 <Java程序设计>结对项目阶段总结<四则运算--整数> 一.需求分析 实现一个命令行程序,要求: 自动生成小学四则运算题目(加,减, ...

  9. 结对项目——四则运算GUI项目

    一.项目地址:https://git.coding.net/lvgx/wsz.git 二.PSP: PSP2.1 任务内容 计划共完成需要的时间(min) 实际完成需要的时间(min) Plannin ...

随机推荐

  1. 《超实用的Node.js代码段》连载一:获取Buffer对象字节长度

    我们知道Node.js框架下的Buffer对象能够对二进制数据提供很好的支持,那么获取一个Buffer对象真实的字节长度则是必须要用到的功能了.Node.js框架为开发人员提供了一个Buffer.by ...

  2. Nginx开启Gzip压缩提高页面加载速度

    本文转自http://www.veryhuo.com/a/view/51706.html,如有侵权,请及时联系转载人删除! 在实际运维中,为了提高web页面的访问加载速度,一般会把静态资源(比如js. ...

  3. [torch] torch.contiguous

    torch.contiguous 作用 连续存储,因为view的操作要求的是连续的内容. 详细 考虑下面的操作,transpose操作只是改变了stride,而实际数组存储的内容并没有得到任何改变,即 ...

  4. 2018.3.12 Leecode习题 给定一个整数数列,找出其中和为特定值的那两个数。

    给定一个整数数列,找出其中和为特定值的那两个数. 你可以假设每个输入都只会有一种答案,同样的元素不能被重用. 示例: 给定 nums = [2, 7, 11, 15], target = 9; 因为 ...

  5. python处理图片的一些操作

    1.把图片分割成一个个竖条: from PIL import Image gap = 20 img_name = '/home/sensetime/000132_11_4.png' im = Imag ...

  6. pysql用类进行封装

    pyMySQL用类进行封装 class SqlHelper(object): def __init__(self): self.connect() def connect(self): self.co ...

  7. Js笔记 14

      <script> // <!-- 课 对象   // //对象的创建方法 // 1.var obj = {} plainobject 对象字面量 对象直接量 // 2.构造函数 ...

  8. 解决cocos simpleAudioEngine播放mp3失败问题

    今天用cocos3.x版本实现游戏音乐播放发现一个坑,策划发来的mp3格式音频,用 simpleAudioEngine无法播放, 以为是路径问题,断点调试没找到,然后拷贝了cocos自带的mp3音频文 ...

  9. cocos2dx 使用XMLHttpRequest时回调status为0的问题

    今天使用cocos连接http访问时,使用XMLHttpRequest在pc上反问时正常的返回了status=0,但是在android上去返回status是0,看了一下底层代码, 发现status只有 ...

  10. SVN:The working copy is locked due to a previous error (二)

    之前也碰到过这种问题,但是根本问题不同,解决方案不同. 传送门:SVN:The working copy is locked due to a previous error (二) 本次错误如图: 解 ...