WordCount结对项目

合作者:201631062429,201631062413

代码地址:https://gitee.com/gitdq/WC2.0

队友博客地址: http://www.cnblogs.com/zjgss9/p/9800534.html

本次作业的链接地址:https://edu.cnblogs.com/campus/xnsy/2018Systemanalysisanddesign/homework/2188

一、PSP表格

PSP

PSP阶段

预估耗时

(分钟)

实际耗时

(分钟)

Planning

计划

         45        

 30

Estimate

估计这个任务需要多少时间

 20

 30

Development

开发

 420

 600

Analysis

需求分析 (包括学习新技术)

 90

 60

Design Spec

生成设计文档

 0

 0

Design Review

设计复审 (和同事审核设计文档)

 30

 15

Coding Standard

代码规范 (为目前的开发制定合适的规范)

 30

 20

Design

具体设计

60

 30

Coding

具体编码

 420

 480

Code Review

代码复审

 90

 120

Test

测试(自我测试,修改代码,提交修改)

 120

 120

Reporting

报告

120

 90

Test Report

测试报告

 15

 30

Size Measurement

计算工作量

 30

 30

Postmortem & Process Improvement Plan

        事后总结, 并提出过程改进计划

 30

 15

 

合计

 1520

 1670

二、代码审核及合并

代码自审 代码互审 代码合并
检查关键部分代码逻辑是否有问题,跟踪参数的值的变化是否存在问题 运行代码,进行基本功能的审查

将各自自审稳定的部分进行选择性地功能整合,再对合并后的版本进行共审,确定为将要使用的基础版本

检查在非法输入时是否有异常抛出 测试代码的稳定性,看程序对异常输入或者其他异常操作能否抛出异常或做相应处理 

  

 

三、设计过程

(1)、结构设计

1.类:

a.Client 客户端

b.Command 命令处理及功能实现

c.WcGUI 界面

2.方法分别为处理命令行参数,对各部分功能实现,读文件函数,以及界面显示等。

如下:

(2)、算法设计流程图

 

四、代码说明

我负责的部分是扩展功能中的递归处理文件和高级功能。

递归处理文件

/**
* 递归计算符合要求文件需要计算的数据的计算方法
* @param fileName 需要计算的含通配符文件
*/
private void recursiveFiles(String fileName){
File dir = new File(".");
//获取当前目录下的所有符合条件的文件
List<File> files = getFile(dir);
for (File file : files) {
if (this.isC) {
charNum(file);
}
if (this.isW) {
wordNum(file);
}
if (this.isL) {
lineNum(file);
}
if (this.isA) {
complexStat(file);
}
}
}
public List<File> getFile(File dir) {
List<File> files = new ArrayList<>();
File[] subs = dir.listFiles();
for (File file : subs) {
//如果this.fileName == null,说明是高级功能GUI在调用,否则为扩展功能调用
if(file.isFile() && this.fileName == null){
files.add(file);
}
else if (file.isFile() && file.getName().endsWith(this.fileName.substring(1))) {
//这里我只处理了*在最前的状态,如*.c,*wc.txt,对于hel*.c的情况处理不了,算法有待优化
files.add(file);
} else if (file.isDirectory()) {
files.addAll(getFile(file));
}
}
return files;
}

高级功能

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;

public class WcGUI {

public void showUI() {
Command cm = new Command();

JFrame f = new JFrame("WordCount");
f.setLayout(null);
JFileChooser fc = new JFileChooser();

JButton bOpenDir = new JButton("打开文件或文件夹并写入");
bOpenDir.setBounds(220,15,180,30);

JButton bResult = new JButton("修改写入文件");
bResult.setBounds(50,15,140,30);

JCheckBox cb = new JCheckBox("使用停用词表");
cb.setBounds(430,15,150,30);

JTextArea ja = new JTextArea();
ja.setFont(new Font("黑体",Font.BOLD,15));
ja.setEditable(false);

JScrollPane jsp=new JScrollPane(ja);
jsp.setBounds(50,50,600,400);

f.add(bOpenDir);
f.add(bResult);
f.add(cb);
f.add(jsp);


f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(700, 500);
f.setLocationRelativeTo(null);
f.setVisible(true);

bOpenDir.addActionListener(e -> {
ja.setText("");
FileSystemView fsv = FileSystemView.getFileSystemView();
//设置当前路径为desktop
fc.setCurrentDirectory(fsv.getHomeDirectory());
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if (fc.showOpenDialog(f) == JFileChooser.APPROVE_OPTION) {
File dir = fc.getSelectedFile();
if (dir.isDirectory()) {
List<File> files = cm.getFile(dir);
for (File file : files) {
ja.append(cm.charNum(file) + cm.wordNum(file)
+ cm.lineNum(file) + cm.complexStat(file) + "\n\n" );
ja.setCaretPosition(ja.getText().length());
}
} else if (dir.isFile()) {
ja.append(cm.charNum(dir) + cm.wordNum(dir)
+ cm.lineNum(dir) + cm.complexStat(dir) + "\n\n" );
ja.setCaretPosition(ja.getText().length());
}
}
});

bResult.addActionListener(e -> {
FileSystemView fsv=FileSystemView.getFileSystemView();
//设置当前路径为desktop
fc.setCurrentDirectory(fsv.getHomeDirectory());
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = fc.showOpenDialog(f);
File file = fc.getSelectedFile();
String selectedFilePath = file.getAbsolutePath();
if (returnVal == JFileChooser.APPROVE_OPTION) {
cm.setOutFile(selectedFilePath);
JOptionPane.showMessageDialog(f, "所选结果写入文件:" + selectedFilePath);
}

});
cb.addActionListener(e -> {
if (cb.isSelected()){
cm.setStopList("stopList.txt");
cm.setE(true);
}else {
cm.setE(false);
}
});
}
}

五、总结

  在这次结对编程项目中,我原本以为是一个主编程员负责编程,一个领航员在旁边纠错以及引导方向,这样一起编一份代码,没想到最后还是成了两个人各写不同部分的代码再总和。不过尽管如此,两个人完成一个项目,还是1+1>2的。

 

posted on 2018-10-17 21:46  塑料组选手  阅读(113)  评论(0编辑  收藏  举报

导航