合作者:201631083310,201631081116


 

代码地址:https://gitee.com/easy-yy/wordcount_full_version


 

作业链接:https://edu.cnblogs.com/campus/xnsy/2018Systemanalysisanddesign/homework/2188


 

代码审核及合并

代码自审

代码互审

代码合并

独自检查文件名,逻辑、以及是否存在不合法的操作

首先运行代码,查看代码是否可以通过并达到预期的目的。

将自审和互审的结果进行讨论,把稳定的部分代码进行标记,提出各自认为好的模块,参考对方的代码进行比较,把稳定性高,更加好的的代码

留下,并在任一一个项目上进行合并,最后两人一起完成审核,测试,并完成扩展功能

检查代码在编码格式,代码结构上是否存在问题。

其次是构建测试类,调用关键的方法去执行,查看是否能通过运行或者抛出异常

检查在关键代码上是否有异常抛出

最后就是测试代码的稳定性,通过多个文件对代码进行测试,查看是否出现异常

 


(1)PSP表格

 

PSP2.1

PSP阶段

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

100

30

Estimate

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

200

300

Development

开发

200

335

Analysis

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

100

223

Design Spec

生成设计文档

80

113

Design Review

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

60

30

Coding Standard

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

90

150

Design

具体设计

200

240

Coding

具体编码

200

300

Code Review

代码复审

180

210

Test

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

250

100

Reporing

报告

40

20

Test Report

测试报告

20

20

Size Measurement

计算工作量

10

50

Postmortem&Process Improvement Plan

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

10

30

 

合计

1740

2151

 

设计项目的流程图:

 

代码情况:本次项目我主要负责界面和代码整合

项目分为3个部分:swingconsole(我自己实现的基础界面类)和Test(相关功能函数)以及test2(界面设计)

1.swingconsole,我设计的一个java界面的基础类,我测试时所用的一个类

 1 public class SwingConsole {
 2     public static void run(final JFrame f,final int width,final int height) {
 3         SwingUtilities.invokeLater(new Runnable() {
 4             @Override
 5             public void run() {
 6                 // TODO Auto-generated method stub
 7                 f.setTitle(f.getClass().getSimpleName());
 8                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 9                 f.setSize(width, height);
10                 f.setVisible(true);
11             }
12         });
13     }
14 }

2.界面UI的相关代码设计

 1 public class test2 extends JFrame{
 2     JTextArea t=new JTextArea(100,50);
 3     final JFileChooser jFileChooser=new JFileChooser();
 4     private JCheckBox
 5         cb1=new JCheckBox("字符统计"),
 6         cb2=new JCheckBox("单词统计"),
 7         cb3=new JCheckBox("行数统计"),
 8         cb4=new JCheckBox("停词表"),
 9         cb5=new JCheckBox("注释行统计");
10     JButton jButton=new JButton("上传文件");    
11     public test2() {
12         jButton.addActionListener(new ActionListener() {
13             @Override
14             public void actionPerformed(ActionEvent arg0) {
15                 // TODO Auto-generated method stub
16                 JFrame j=new JFrame();
17                 int fileName=jFileChooser.showOpenDialog(j);    
18                 File jFile=jFileChooser.getSelectedFile();
19                 String selectPath=jFile.getAbsolutePath();
20                 if (fileName==jFileChooser.APPROVE_OPTION) {
21                     JOptionPane.showMessageDialog(j, selectPath);
22                 }
23                 cb1.addActionListener(new ActionListener() {
24                     @Override
25                     public void actionPerformed(ActionEvent e) {    
26                         t.append("字符数:"+String.valueOf(Test.num_of_char(selectPath))+"\n");
27                     }
28                 });
29                 cb2.addActionListener(new ActionListener() {
30                     @Override
31                     public void actionPerformed(ActionEvent e) {
32                         t.append("单词统计:"+String.valueOf(Test.num_of_word(selectPath))+"\n");
33                     }
34                 });
35                 cb3.addActionListener(new ActionListener() {
36                     @Override
37                     public void actionPerformed(ActionEvent e) {
38                         t.append("行数统计:"+String.valueOf(Test.num_of_line(selectPath))+"\n");
39                     }
40                 });
41                 cb4.addActionListener(new ActionListener() {
42                     @Override
43                     public void actionPerformed(ActionEvent e) {
44                         t.append("停词表:"+String.valueOf(Test.num_of_word_e(selectPath))+"\n");
45                     }
46                 });
47                 cb5.addActionListener(new ActionListener() {
48                     @Override
49                     public void actionPerformed(ActionEvent e) {
50                         t.append("注释行:"+String.valueOf(Test.code_ana(selectPath))+"\n");
51                     }
52                 });
53             }
54         });    
55         setLayout(new FlowLayout());
56         add(new JScrollPane());
57         add(cb1);add(cb2);add(cb3);
58         add(cb4);add(cb5);add(jButton);add(t);    
59     }
60 }

扩展功能等展示一部分:停词表和注释等功能实现

 1  //使用停词表
 2     public static int num_of_word_e(String filename) {
 3         // TODO Auto-generated method stub
 4         File file=new File(filename);
 5         File stopfile=new File(stoplist);
 6         ArrayList<String> stopstr = new ArrayList<String>();
 7         Reader readfile=null;
 8         boolean letter_flag=false;
 9         int w_num=0;
10         //读取停用词表内容,保存在stopstr中
11         try{
12             readfile = new InputStreamReader(new FileInputStream(stopfile));
13             int tempchar;
14             String str="";
15             while ((tempchar=readfile.read()) != -1) {
16                 if(IsLetter((char)tempchar)){
17                     letter_flag=true;
18                     str+=(char)tempchar;
19                 }
20                 else if(letter_flag==true){
21                     letter_flag=false;
22                     stopstr.add(str);
23                     str="";
24                 }
25             }
26             readfile.close();
27         }
28         catch(Exception e){
29             e.printStackTrace();
30         }
31         //判断word数
32         try{
33             readfile = new InputStreamReader(new FileInputStream(file));
34             int tempchar;
35             String str="";
36             while ((tempchar=readfile.read()) != -1) {
37                 if(IsLetter((char)tempchar)){
38                     letter_flag=true;
39                     str+=(char)tempchar;
40                 }
41                 else if(letter_flag==true){
42                     letter_flag=false;
43                     w_num++;
44                     for(int i=0;i<stopstr.size();i++){
45                         if(str.compareTo(stopstr.get(i))==0){
46                             w_num--;
47                         }
48                     }
49                     str="";
50                 }
51             }
52             readfile.close();
53         }
54         catch(Exception e){
55             System.out.println("指定输入文件不存在");
56         }
57         return w_num;
58     }
 1  //空行、代码行、注释行统计
 2     public static String code_ana(String filename){
 3         String num1;
 4         File file=new File(filename);
 5         int nothing=0;
 6         int line=0;
 7         int note=0;
 8         int code_line=0;
 9         boolean note_flag=false;
10         BufferedReader readfile = null;
11         try{
12             readfile = new BufferedReader(new FileReader(file));
13             String tempString = null;
14             while ((tempString = readfile.readLine()) != null) {
15                 line++;
16                 tempString=tempString.replaceAll("\r\n"," ");//去掉所有换行符和空格
17                 if(note_flag==true){
18                     note++;
19                     if(tempString.endsWith("*/")){
20                         note_flag=false;//代表注释内容在本行结束
21                     }
22                 }
23                 if(tempString.equals(" ")||tempString.equals("{")||tempString.equals("}")){
24                     nothing++;
25                 }
26                 if(tempString.startsWith("//")||tempString.startsWith("{//")){
27                     note++;
28                 }
29                 if(tempString.startsWith("/*")||tempString.startsWith("{/*")){
30                     if(tempString.endsWith("*/")){
31                         note++;
32                     }
33                     else{
34                         note++;
35                         note_flag=true;//代表注释的内容在本行还没结束
36                     }
37                 }
38                 code_line=line-note-nothing;
39             }
40             readfile.close();
41         }
42         catch(Exception e){
43             System.out.println("指定输入文件不存在");
44         }
45         num1="代码行:"+code_line+"空行:"+nothing+"注释:"+note;         
46         return num1;
47     }

项目结果展示:

选择不同的功能,下面文本框中输出不同的结果:

项目总结:

  本次项目出现了许多问题,但是在我们共同的努力下也完成了整个项目的完成。在代码复审和整合阶段比较难,以为写代码的风格不同,我需要对看明白对方的代码,在整合完以后也对代码整合有了经验,直接调用相关功能就行。两个人一起配合做还是有非常好的,大大提高了编程的效率,而且有问题也可以一起解决,可以尝试不同的思路。

 

posted on 2018-10-16 20:28  Easy丶yy  阅读(386)  评论(0编辑  收藏  举报