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

软件工程firstblood的更多相关文章

  1. 软件工程(C编码实践篇)学习心得

    孟繁琛 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程 http://mooc.study.163.com/course/USTC-1000002006 软件工程 ...

  2. 敏捷软件开发VS传统软件工程

    敏捷软件开发:又称敏捷开发,是一种从1990年代开始逐渐引起广泛关注的一些新兴软件开发方法,是一种应对快速变化的需求的一种软件开发能力. 与传统软件工程相比,它们的具体名称.理念.过程.术语都不尽相同 ...

  3. Atitit 软件工程概览attilax总结

    Atitit 软件工程概览attilax总结 1.1. .2 软件工程的发展 进一步地,结合人类发展史和计算机世界演化史来考察软件工程的发展史. 表2 软件工程过程模型 表2将软件工程的主要过程模型做 ...

  4. 软件工程的引入:Scrum开发框架总结

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点如下: 软件工程概念 敏捷开发过程scrum 一.什么是软件工程?请用一句话描述. 软件工程是一门研究性的学科:它用工程化 ...

  5. 软件工程里的UML序列图的概念和总结

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...

  6. 软件工程随笔(1)--jetbrain在软件工程中的应用

    接下来几天我要写半年的软件工程学习后的感想,今天从介绍IDE开始.首先,本人至今为止全部项目都是在mypclise上完成的.本人采用myeclipse唯一的原因就是它使用方便.但是,我也承认myecl ...

  7. 2016福州大学软件工程第三次个人作业-K米软件产品评测

    K米软件测评个人作业结果统计如下: 评分标准: 按照栋哥布置的第三次个人作业--K米测评制定评分标准如下: 第一部分:调研.评测 下载并使用,描述最简单直观的个人第一次上手体验. 0.5 按照描述的b ...

  8. 软件工程(QLGY2015)博客点评总结

    目录 第一次作业(2015.5.9) 第二次作业(2015.5.21) 第三次作业(2015.6.11) 2015上半年软工助教总结 第一次作业(2015.5.9) 存在主要问题 1)书写这种练习博客 ...

  9. 软件工程-构建之法 Visual Studio开发平台的安装与单元测试

    一.前言 自从开始了大三下的生活,学校开设一门课程“软件工程”,刚好我们是第一届进行课程改革,不在像以前那样背背概念,考前进行好好突击,然后考试就能过,最后毕业了发现软件工程课程到底我们在其中学习了什 ...

随机推荐

  1. 爬虫Scrapy框架

    安装scrapy 在安装过程中报错:解决方案 通过在https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted,然后下载: CP后是python 版本,32 ...

  2. EOS token 代币兑换的资料

    eos token 兑换价格预估查询:   https://eosscan.io/ https://steemit.com/eos/@sandwich/how-to-check-which-eos-p ...

  3. 记录:EPALN Electric P8 2.4.4.8366 安装记录

    系统:win7  32位 旗舰版.  (原版系统 非GHOST) 第一步:解压安装. setup.exe 右击 选择 注意:把  360  百度 杀毒之类的全部关闭 第二步: 第三步: 第四步: 第五 ...

  4. 转载Liferay PortletPreference store()方法研究

    我们对于PortletPreference 的store()用的非常广泛,很多情况下,我们一般对其进行一些设定,然后最后调用store()存储之,类似以下代码: PortletPreferences ...

  5. 141. Linked List Cycle(判断链表是否有环)

    141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you sol ...

  6. Python: 复数的数学运算

    写的最新的网络认证方案代码遇到了一个难题,唯一的解决办法就是使用复数空间,需要使用复数来执行一些计算操作. 复数可以用使用函数complex(real, imag) 或者是带有后缀j 的浮点数来指定. ...

  7. Android开发--取消AsyncTask

    在Android应用开发过程中,为了防止UI线程堵塞,耗时的工作都应该另起一个后台线程来完成,其中AsyncTask就是其中的一种方式.最近在案子中需要“停止/取消”某个AsyncTask,在网上查了 ...

  8. 常用技巧之JS判断数组中某元素出现次数

    先上代码:function arrCheck(arr){  var newArr = [];  for(var i=0;i<arr.length;i++){    var temp=arr[i] ...

  9. javascript原生事件总结

    javascript原生的事件,总结了一下,包括事件流.处理函数.事件对象这几样东西.而在兼容性方面,主要是老牌ie8以及以下和现代浏览器的差异,也就是ie和DOM事件标准的差异. 事件流这个事件流i ...

  10. poj2262 Goldbach's Conjecture

    poj2262 Goldbach's Conjecture 用欧拉筛把素数筛出来,再枚举一下. #include<iostream> #include<cstdio> #inc ...