结队编程-WordCount
合作者:
201631062201,201631062202
代码地址:
https://gitee.com/ZMLJZ/codes/3os7pwfqz58unil9c1xag30#WordCount.java
作业链接:
https://edu.cnblogs.com/campus/xnsy/2018Systemanalysisanddesign/homework/2188
代码审核及合并
回观我们的第一次项目,我们都并没自审我们的代码,也没有做很严谨的测试。结对项目中我们相互对对方的代码进行了审核,张明磊同学认为奂欣同学的代码,将所有的任务都放在了主函数里,造成依赖过重,奂欣同学认为张明磊同学的代码代码结构挺好的,但是不够完善,读取文件那里有待改进。最后两个人将代码合并实现该项目的扩展和高级功能。
具体的审核如下表:
|
代码自审 |
代码互审 |
代码合并 |
|
独自检查文件名,逻辑、以及是否存在不合法的操作 |
首先运行代码,查看代码是否可以通过并达到预期的目的。 |
将自审和互审的结果进行讨论,把稳定的部分代码进行标记,提出各自认为好的模块,参考对方的代码进行比较,把稳定性高,更加好的的代码 留下,并在任一一个项目上进行合并,最后两人一起完成审核,测试,并完成扩展功能 |
|
检查代码在编码格式,代码结构上是否存在问题。 |
其次是构建测试类,调用关键的方法去执行,查看是否能通过运行或者抛出异常 |
|
|
检查在关键代码上是否有异常抛出 |
最后就是测试代码的稳定性,通过多个文件对代码进行测试,查看是否出现异常 |
(1)PSP表格
|
PSP2.1 |
PSP阶段 |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
100 |
300 |
|
Estimate |
估计这个任务需要多少时间 |
120 |
100 |
|
Development |
开发 |
500 |
1000 |
|
Analysis |
需求分析(包括学习新技术) |
180 |
300 |
|
Design Spec |
生成设计文档 |
80 |
90 |
|
Design Review |
设计复审(和同事审核设计文档) |
60 |
30 |
|
Coding Standard |
代码规范(为目前的开发指定合适的规范) |
90 |
150 |
|
Design |
具体设计 |
200 |
240 |
|
Coding |
具体编码 |
400 |
480 |
|
Code Review |
代码复审 |
180 |
210 |
|
Test |
测试(自我测试,修改代码,提交修改) |
200 |
250 |
|
Reporing |
报告 |
20 |
60 |
|
Test Report |
测试报告 |
30 |
50 |
|
Size Measurement |
计算工作量 |
30 |
50 |
|
Postmortem&Process Improvement Plan |
事后总结,并提出过程改进计划 |
30 |
60 |
|
|
合计 |
2220 |
3370 |
代码说明
统计文件字符的相关代码:根据符号将文本分割,分别统计字符数,单词数和行数
public void doCount(String inputFile) throws IOException {
String txt = "";
String[] buffer;
File dir = new File(inputFile);
BufferedReader bf = new BufferedReader( new FileReader(dir) );
while( (txt = bf.readLine()) != null ){
buffer = txt.split(", | |\t |\n");//根据字符切分
for(int i = 0 ; i < buffer.length ; i++){
if( !buffer[i].equals(""))
count.setWordNumber( count.getWordNumber()+1 );//统计单词数
}
count.setLineNumber( count.getLineNumber()+1 );//统计行数
count.setCharNumber( count.getCharNumber() + txt.length() );//统计字符数
}
bf.close();
}
创建窗口并设置两个按钮
CrateJFrame(title); c = jf.getContentPane(); setLayout();
JButton choseFile = new JButton("选择文件");
choseFile.addActionListener(new choseFileAction());
c.add(choseFile);
JButton outputFile = new JButton("生成统计文件");
outputFile.addActionListener(new outputFileAction());
c.add(outputFile);
利用内部类设置按钮的监听事件,选择文件是记录所选择的文件路径,生成统计文件是根据所选择的文件生成一个存有统计结果的文件:
class choseFileAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser jfc=new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
jfc.showDialog(new JLabel(), "选择");
File file=jfc.getSelectedFile();
inputFile = file.getAbsolutePath();
fileName = file.getName();
}
}
class outputFileAction implements ActionListener{
@Override
public void actionPerformed(ActionEvent arg0){
try {
//读入test.c文件
String inputFile = getInputFile();
WordCount wc = new WordCount();
wc.doCount(inputFile);
String output = inputFile.replace(".", "_output.");
//将结果写入output.txt
File resultFile = new File(output);
resultFile.createNewFile();
BufferedWriter out = new BufferedWriter( new FileWriter(resultFile) );
out.write("字符数:"+wc.getCount().getCharNumber());
out.newLine();
out.write("单词数:"+wc.getCount().getWordNumber());
out.newLine();
out.write("行数:"+wc.getCount().getLineNumber());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行效果:

选择文件

生产的统计文件都保存在选择文件同目录下:

Txt文件

总结:
一个人做确实比不上结对的效率,互审可以比自审更加清楚的发现自己的问题,遇到了问题也可以更好的给予帮助,因为是两个人,不容易产生分歧,面对小问题也更容易想到解决办法。

浙公网安备 33010602011771号