软工作业WordCount

github项目传送门:https://github.com/zzh010/My-wc

一、WC 项目要求

wc.exe 是一个常见的工具,它能统计文本文件的字符数、单词数和行数。这个项目要求写一个命令行程序,模仿已有wc.exe 的功能,并加以扩充,给出某程序设计语言源文件的字符数、单词数和行数。

实现一个统计程序,它能正确统计程序文件中的字符数、单词数、行数,以及还具备其他扩展功能,并能够快速地处理多个文件。
具体功能要求:
程序处理用户需求的模式为:

wc.exe [parameter] [file_name]

基本功能列表:

wc.exe -c file.c     //返回文件 file.c 的字符数

wc.exe -w file.c    //返回文件 file.c 的词的数目  

wc.exe -l file.c      //返回文件 file.c 的行数

二、PSP开发耗时

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

60

80

· Estimate

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

40

40

Development

开发

200

250

· Analysis

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

60

60

· Design Spec

· 生成设计文档

60

60

· Design Review

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

60

60

· Coding Standard

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

40

40

· Design

· 具体设计

60

60

· Coding

· 具体编码

120

120

· Code Review

· 代码复审

60

60

· Test

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

40

40

Reporting

报告

30

30

· Test Report

· 测试报告

30

40

· Size Measurement

· 计算工作量

30

30

· Postmortem & Process Improvement Plan

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

20

20

合计

910

990

三、设计实现

readLine每次读取一行

countChar += s.length()  实现字符个数的统计

countword += s.split(" ").length  split() 方法用于把一个字符串分割成字符串数组,实现单词个数的统计

countline++  通过按行读取,所以每次增加一即可计算出行的数目

四、关键代码

public class wordcounter {


public static void main(String[] args) throws Exception {
  
    
  Scanner input = new Scanner(System.in);
  System.out.println("please input path:");
  String path = input.next();
  int countChar = 0;
  int countword = 0;
  int countline = 0;
  InputStreamReader isr = new InputStreamReader(new FileInputStream(path));
 
  Bufferedreader br = new BufferedReader(isr);

  while(br.read()!=-1)
 
  {
   String s = br.readLine();
   countChar += s.length();
   countword += s.split(" ").length;
   countline++;
  }
  isr.close();
  System.out.println("char cont "+countChar);
  System.out.println("word count "+countword );
  System.out.println("line count "+countline); 
  }
}

五、测试运行

测试文档

测试结果

六 、项目小结

通过本次作业,我了解到了软件工程设计的主要流程和要点,了解到前期对于项目的分析在整个设计的过程中是非常重要的,由于之前对java知识掌握得不够,导致本次作业进度做得比较慢。但是这次作业也重新让我回顾了java知识,对我以后的项目开发起到较大的帮助。本次项目仍有没能实现的扩展功能,希望能够在接下来的过程中不断完善。

猜你喜欢

转载自www.cnblogs.com/zero010/p/9698750.html
今日推荐