博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件工程firstblood
阅读量:4448 次
发布时间:2019-06-07

本文共 3013 字,大约阅读时间需要 10 分钟。

https://github.com/happyeven/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 的行数

关键代码or设计说明

1.单词、行数、字符的计数

public class Counter {private long character;private long word;private long line;private String text;private long countChar() {return text.length();}private long countWord() {boolean blank = true;long word = 0;for (char c : text.toCharArray()) {if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')){if (blank){blank = false;word++;}}else if (c == '-' && !blank){continue;}else {blank = true;}}return word;}private long countLine() {long line = 0;int index = -1;while((index=text.indexOf("\n", index)) > -1) {index++;line++;}return line;}public Counter(String text) {this.text = text;}public void count() {character = countChar();word = countWord();line = countLine();}public long getWord() {return word;}public long getLine() {return line;}public long getCharacter() {return character;}} 2文件的读取并转换成string类型import java.io.*;public class ReadFileToString {  public static String readFileToString(String fileName) {    File file = new File(fileName);    Long length = file.length();    byte[] bytes = new byte[length.intValue()];    try {      FileInputStream in = new FileInputStream(file);      in.read(bytes);      in.close();  } catch (FileNotFoundException e) {    e.printStackTrace();  } catch (IOException e) {    e.printStackTrace();  }  return new String(bytes);  }}3主类,输出需要的结果public class WC {public static void main(String[] args) {  String path = args[args.length-1];      // get the file  if (args.length <= 0){  System.err.println("please input the argument");  return;  }  String text = ReadFileToString.readFileToString(path);        // count   Counter counter = new Counter(text);   counter.count();        // output result  System.out.print(path + ": ");  for (int i = 0; i < args.length-1; i++) {  switch (args[i]) {  case "-c" :System.out.print("Character: " + counter.getCharacter() + " "); break;  case "-w" : System.out.print("word: " + counter.getCharacter() + " "); break;  case "-l" : System.out.print("line: " + counter.getCharacter() + " "); break;  default: break;        }      }    }}

  

PSP

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

 

转载于:https://www.cnblogs.com/happyeven/p/9649086.html

你可能感兴趣的文章
setAdapter(adapter)空指针nullPointer 解决办法 分类: ...
查看>>
【JEECG技术文档】数据权限自定义SQL表达式用法说明
查看>>
使用 Bootstrap Typeahead 组件
查看>>
第一次玩蛇,有点紧张。
查看>>
DAO层,Service层,Controller层、View层 的分工合作
查看>>
EF不能很好的支持DDD?估计是我们搞错了!
查看>>
用户登录安全框架shiro—用户的认证和授权(一)
查看>>
提取图片的文字
查看>>
Supports BorlandIDEServices
查看>>
SVM-支持向量机算法概述
查看>>
ios开发零食
查看>>
Coursera台大机器学习技法课程笔记01-linear hard SVM
查看>>
机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)
查看>>
Bag of Tricks for Image Classification with Convolutional Neural Networks论文笔记
查看>>
MACE环境搭建
查看>>
SD 信贷出口 备忘
查看>>
iOS正确的自定义View方式
查看>>
nginx修改php.ini生效:php-fpm重启与nginx加载配置文件
查看>>
ubuntu下基于sqlite3后台的php环境的搭建
查看>>
Qt 静态库与共享库(动态库)共享配置的一个小办法
查看>>