软件工程firstblood
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的更多相关文章
- 软件工程(C编码实践篇)学习心得
孟繁琛 + 原创作品转载请注明出处 + <软件工程(C编码实践篇)>MOOC课程 http://mooc.study.163.com/course/USTC-1000002006 软件工程 ...
- 敏捷软件开发VS传统软件工程
敏捷软件开发:又称敏捷开发,是一种从1990年代开始逐渐引起广泛关注的一些新兴软件开发方法,是一种应对快速变化的需求的一种软件开发能力. 与传统软件工程相比,它们的具体名称.理念.过程.术语都不尽相同 ...
- Atitit 软件工程概览attilax总结
Atitit 软件工程概览attilax总结 1.1. .2 软件工程的发展 进一步地,结合人类发展史和计算机世界演化史来考察软件工程的发展史. 表2 软件工程过程模型 表2将软件工程的主要过程模型做 ...
- 软件工程的引入:Scrum开发框架总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点如下: 软件工程概念 敏捷开发过程scrum 一.什么是软件工程?请用一句话描述. 软件工程是一门研究性的学科:它用工程化 ...
- 软件工程里的UML序列图的概念和总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...
- 软件工程随笔(1)--jetbrain在软件工程中的应用
接下来几天我要写半年的软件工程学习后的感想,今天从介绍IDE开始.首先,本人至今为止全部项目都是在mypclise上完成的.本人采用myeclipse唯一的原因就是它使用方便.但是,我也承认myecl ...
- 2016福州大学软件工程第三次个人作业-K米软件产品评测
K米软件测评个人作业结果统计如下: 评分标准: 按照栋哥布置的第三次个人作业--K米测评制定评分标准如下: 第一部分:调研.评测 下载并使用,描述最简单直观的个人第一次上手体验. 0.5 按照描述的b ...
- 软件工程(QLGY2015)博客点评总结
目录 第一次作业(2015.5.9) 第二次作业(2015.5.21) 第三次作业(2015.6.11) 2015上半年软工助教总结 第一次作业(2015.5.9) 存在主要问题 1)书写这种练习博客 ...
- 软件工程-构建之法 Visual Studio开发平台的安装与单元测试
一.前言 自从开始了大三下的生活,学校开设一门课程“软件工程”,刚好我们是第一届进行课程改革,不在像以前那样背背概念,考前进行好好突击,然后考试就能过,最后毕业了发现软件工程课程到底我们在其中学习了什 ...
随机推荐
- 以太坊geth主网全节点部署
以太坊geth主网全节点部署 #环境 ubuntu 16.4 #硬盘500GB(目前占用200G) #客户端安装 # 查看下载页面最新版 # https://ethereum.github.io/go ...
- android ListView几个有用的属性
1. stackFromBottom,设置为ture你做好的列表就会显示你列表的最下面 2. transciptMode,通过设置的控件transcriptMode属性可以将Android平台的控件( ...
- Keras常用层
Dense层:全连接层 Activatiion层:激活层,对一个层的输出施加激活函数 Dropout层:为输入数据施加Dropout.Dropout将在训练过程中每次更新参数时按一定概率(rate)随 ...
- cocos2d-x-3.0 window+eclipse Android Project 环境与开发新手教程
今天闲来没事,听说最新cocos2d-x 出新版3.0.所以来学习一下. 大致參考官方教程:http://www.cocos2d-x.org/wiki/How_to_Build_an_Android_ ...
- 创建WCF服务的过程
一.创建控制台WCF工程 1.创建一个控制台工程2.System.ServiceModel的引用3.可创建多个WCF服务,如:IService.cs和Service.cs 顺序:右键->添 ...
- easyUI datagrid 清空
最近在做一个管理系统,出于一些需要,经常要将一些datagrid清空.然后easyUI本身并没有自带的方法,然后自己动手丰衣足食吧. 清空无外乎两种思路,删除现有数据和填充空数据. 1.删除数据 va ...
- python之WebSocket协议
一.WebSocket理论部分 1.websocket是什么 Websocket是html5提出的一个协议规范,参考rfc6455. websocket约定了一个通信的规范,通过一个握手的机制,客户端 ...
- PAT 1088 Rational Arithmetic[模拟分数的加减乘除][难]
1088 Rational Arithmetic(20 分) For two rational numbers, your task is to implement the basic arithme ...
- 数据挖掘-关联分析 Apriori算法和FP-growth 算法
•1.关联分析概念 关联分析是从大量数据中发现项集之间有趣的关联和相关联系. •定义:1.事务:每一条交易称为一个事务,如上图包含5个事务.2.项:交易的每一个物品称为一个项,例如豆奶,啤酒等. ...
- Amber安装并行
现在简单介绍一下amber12中安装openmpi并行的过程. 1. 下载openmpi版本在1.5-1.9之间的(openmpi-1.6.5.tar.bz2) 这是因为$AMBERHOME/Ambe ...