1. 博客地址
2. 结对小伙伴的学号、博客地址,结对项目的码云地址
| 成员学号 | 成员姓名 | 项目地址 |
|---|---|---|
| 201621123008 | 周文华 | https://www.cnblogs.com/Dzwh/ |
| 201621123002 | 肖文婷 | |
| . | . | https://gitee.com/Dzwh/PairProject-Java/tree/master/008-002 |
3. 结对的PSP表格
| PSP2.2 | 结对开发流程 | 结对开发流程 | 实际耗费时间(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 50 |
| Estimate | 明确需求和其他相关因素,估计每个阶段的时间成本 | 50 | 70 |
| Development | 开发 | 650 | 700 |
| Analysis | 需求分析 (包括学习新技术) | 500 | 650 |
| Design Spec | 生成设计文档 | 100 | 150 |
| Design Review | 设计复审 | 60 | 70 |
| Coding Standard | 代码规范 | 50 | 30 |
| Design | 具体设计 | 200 | 160 |
| Coding | 具体编码 | 180 | 200 |
| Code Review | 代码复审 | 60 | 50 |
| Test | 测试(自我测试,修改代码,提交修改) | 60 | 190 |
| Reporting | 报告 | 100 | 190 |
| · | 测试报告 | 40 | 40 |
| · | 计算工作量 | 60 | 60 |
| · | 并提出过程改进计划 | 50 | 30 |
4. 解题思路
-
编程语言:java
-
编译环境:eclipse,netbrans
-
具体思路:本次实验在上次的基础上稍加一些条件限制即可实现新增功能。使用netbeans实现GUI界面的搭建,通过使用JFilechooser控件实现用户对文件的选择,通过调用其成员函数即可得到待统计文件的路径,然后将其路径以字符串的形式作为参数传递给相应的逻辑处理对象,逻辑处理过程与控制台下相同。当用户点击选择文件按钮时,触发事件,跳出文件选择框,而后获得用户选择文件的路径;用户也可对输出的单词的长度进行限制,只需在遍历时加入相应条件即可;对输出单词的限制可通过对循环的次数进行限制即可。
5. 设计实现过程
1. 相关类
-
FileUtil:存放与文件读写相关的方法。
-
WordUtil:存放对单词进行排序分类等相关操作。
-
Main: 测试类
2 . 对应方法
FileUtil类:
- readFile方法:读取文档,并对其中字符进行统计。
WordUtil类
- sortWord方法:对单词进行排序输出。
3. 单元测试
由于本次是对GUI界面的测试,故采用了netbeans内部的分析IDE

调试过程:



6. 代码说明
private void choiceActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser=new JFileChooser();
int returnVal=chooser.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
filename.setText(chooser.getSelectedFile().getPath());
String path=chooser.getSelectedFile().getPath();
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
FileRead fileRead = new FileRead();
WordCount count=fileRead.readTxtFile(path);
if(count==null){
}else{
List<Map.Entry<String,String>> list=count.sortMap();
characters.setText(String.valueOf(count.getCharacters()));
Words.setText(String.valueOf(count.getWords()));
lines.setText(String.valueOf(count.getLines()));
System.out.println("characters:"+count.getCharacters());
System.out.println("words:"+count.getWords());
System.out.println("lines:"+count.getLines());
String ss="";
if(list.size()<10){
for(int i=0;i<list.size();i++){
ss=ss+"<"+list.get(i).getKey()+">:"+list.get(i).getValue()+"
";
}
other.setText(ss);
} else{
ss="";
for(int i=0;i<10;i++){
ss=ss+"<"+list.get(i).getKey()+">:"+list.get(i).getValue()+"
";
}
other.setText(ss);
}
}
}
}
分析: 当用户点击选择文件按钮时触发相应事件。在其对应的逻辑处理函数中先生成一个JFilechooser对象,调用其showOpenDialog(this)方法弹出文件选择框,新建局部变量保存文件的路径,后将该路径交给相应处理对象,最后将结果输出到文本域中。
Scanner sc=new Scanner(System.in);
System.out.println("查询单词的长度:");
int num=sc.nextInt();
FileRead fileRead = new FileRead();
WordCount count = fileRead.readTxtFile("test\classes\1.txt");
if (count == null) {
System.out.println("文件里的数据为空");
} else {
List<Map.Entry<String, String>> list = count.sortMap();
System.out.println("characters:" + count.getCharacters());
System.out.println("words:" + count.getWords());
System.out.println("lines:" + count.getLines());
if (list.size() < 10) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getKey().length() == num || num==0) {
System.out.println("<" + list.get(i).getKey() + ">:" + list.get(i).getValue());
}
}
} else {
for (int i = 0; i < 10; i++) {
if (list.get(i).getKey().length() == num || num==0) {
System.out.println("<" + list.get(i).getKey() + ">:" + list.get(i).getValue());
}
}
}
}
System.out.println(args);
}
分析:用户可任意输入单词的长度,当用户输入0时默认输出全部统计结果。
7. 结合在构建之法中学习到的相关内容与结对项目的实践经历,描述结对的感受,是否1+1>2?
通过这次的结对编程,让我们体会到了合作的重要性。两个人先把整个程序的框架定下来,然后分别去写不同的模块,两人协作构建,编写,测试代码,让软件开发的效率高了很多。我们在讨论中,常常忽然就会有一个灵感突然来袭,或者是会有一些之前不懂得地方,可能一下就懂了。结对编程的时候乐子多,我们合作的很开心,这样能提高我们的激情,同时也就提高了效率,工作起来很带劲。
