软件测试第二周个人作业WordCount

 

 

软件测试第二周个人作业WordCount

**github地址:https://github.com/kongweixu/WordCount

一.PSP表格

 

PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)
Planning计划20分钟30分钟
· Estimate· 估计这个任务需要多少时间2天3天
Development开发2天2天
· Analysis· 需求分析 (包括学习新技术)2天1天
· Design Spec· 生成设计文档--
· Design Review· 设计复审 (和同事审核设计文档)--
· Coding Standard· 代码规范 (为目前的开发制定合适的规范)20分钟20分钟
· Design· 具体设计2小时3小时
· Coding· 具体编码4天3天
· Code Review· 代码复审0.5天0.5天
· Test· 测试(自我测试,修改代码,提交修改)0.5天0.5天
Reporting报告30分钟30分钟
· Test Report· 测试报告30分钟30分钟
· Size Measurement· 计算工作量2小时1小时
· Postmortem & Process Improvement Plan· 事后总结, 并提出过程改进计划1小时0.5小时
 合计10天10天

二、解题思路

真·多年不碰JAVA,完全忘了java咋写了。选择了eclipse写,主要通过百度搜索了解每一个函数的使用方法,咋依葫芦画瓢去写。具体方法主要是分为读取函数方法和计算方法,读取文件之后调用计算方法,根据读取到的参数来决定输出的内容

三、代码说明

 

  • 统计单词数的代码

总体大致相同,便贴出统计单词数部分的代码!

    public int charCounts(File f) throws Exception{
String str;
int charCount = 0;
BufferedReader br=new BufferedReader(new FileReader(f));
while((str=br.readLine())!=null){
charCount += str.length();
}
File fs=new File("result.txt");
FileWriter fw = new FileWriter(fs, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(f.getName()+",字符数: "+charCount);
pw.flush();
fw.flush();
pw.close();
fw.close();
return charCount;
  • 停用词表


public void stopWords(File f) throws Exception{
String str;
int wordCount=0;
int stopWord=0;
BufferedReader br=new BufferedReader(new FileReader(f));
while((str=br.readLine())!=null){
String []line= str.split(",| ");
wordCount+=line.length;
for(int i=0;i<line.length;i++){
if(line[i].equals("while"))stopWord++;
if(line[i].equals("if"))stopWord++;
if(line[i].equals("switch"))stopWord++;
}
}
int count =wordCount-stopWord;
File fs=new File("result.txt");
FileWriter fw = new FileWriter(fs, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(f.getName()+",单词数: "+count);
pw.flush();//flush实际上就是将所有的写入的流,一次性输出到文件中,之后进行关闭即可。如果没关闭流,也没进行flush,此时的内容并未写入到文件的。
fw.flush();
pw.close();
fw.close();
}
  • 递归处理目录下符合条件的文件

    public ArrayList<File> recursion(String filedir) throws Exception{


    //ArrayList<File> listFiles=new ArrayList<File>();
    File file=new File(filedir);
    File []files=file.listFiles();
    if(files==null)return null;
    for(File f:files){
    if(f.isFile()){
    if(f.getName().endsWith(".c")){
    fileList.add(f);
    }
    }else if(f.isDirectory()){
    recursion(f.getAbsolutePath());
    }
    }
    return fileList;
    }
  • 参数解析


public void complex(File f) throws Exception{
String str;
boolean nodeflag = false;
int codeLine = 0;
int spaceLine = 0;
int nodeLine = 0;
BufferedReader br =new BufferedReader(new FileReader(f));
while((str=br.readLine())!=null){
if(str.matches("\\s*/\\*.*")&&str.matches(".*\\*/\\s*")){
nodeLine++;
      continue;
}
else if(str.matches("\\s*|}\\s*|\\{\\s*")){
spaceLine++;
}
else if(str.matches("//.*")){
nodeLine++;
}else if(str.matches("\\s*/\\*.*")){
nodeLine++;
nodeflag = true;
}else if(str.matches(".*\\*/\\s*")){
nodeLine++;
nodeflag = false;
}else if(nodeflag)nodeLine++;
else codeLine++;
}
File fs=new File("result.txt");
FileWriter fw = new FileWriter(fs, true);
PrintWriter pw = new PrintWriter(fw);
pw.println(f.getName()+",代码行/空行/注释行: "+codeLine+"/"+spaceLine+"/"+nodeLine);
pw.flush();//flush实际上就是将所有的写入的流,一次性输出到文件中,之后进行关闭即可。如果没关闭流,也没进行flush,此时的内容并未写入到文件的。
fw.flush();
pw.close();
fw.close();
}

 

四、测试

 

五、参考链接

 

转载于:https://www.cnblogs.com/kongweixu/p/8613617.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值