java实现wc.exe
Github地址:https://github.com/ztz1998/wc/tree/master
项目相关要求
实现一个统计程序,它能正确统计程序文件中的字符数、单词数、行数,以及还具备其他扩展功能,并能够快速地处理多个文件。
具体功能要求:
基本功能列表:
wc.exe -c file.c //返回文件 file.c 的字符数(实现)
wc.exe -w file.c //返回文件 file.c 的词的数目 (实现)
wc.exe -l file.c //返回文件 file.c 的行数(实现)
扩展功能:
wc.exe -s 递归处理目录下符合条件的文件。(未实现)
wc.exe -a 返回更复杂的数据(代码行 / 空行 / 注释行)。(未实现)
PSP2.1表格
|
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
30 | 40 |
|
· Estimate |
· 估计这个任务需要多少时间 |
30 | 40 |
|
Development |
开发 |
300 | 500 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
60 | 100 |
|
· Design Spec |
· 生成设计文档 |
20 | 0 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
30 | 60 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 | 20 |
|
· Design |
· 具体设计 |
30 | 40 |
|
· Coding |
· 具体编码 |
30 | 50 |
|
· Code Review |
· 代码复审 |
0 | 0 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
30 | 30 |
|
Reporting |
报告 |
120 | 150 |
|
· Test Report |
· 测试报告 |
10 | 20 |
|
· Size Measurement |
· 计算工作量 |
20 | 20 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
10 | 10 |
|
合计 |
730 | 1080 |
解题思路
大二时学java时候,最后一个作业的第一步就是读取文件,也在网上搜索了WordCounter代码,两项结合,思路就基本出来了。结合开发语言写出实现函数所用的方法,通过网上查阅资料开始编写代码,修改代码。
设计
代码分为两个,一个是菜单(主代码,启动程序),一个是运算(逻辑函数代码),通过对应的命令来控制功能,最后输出。
变量:chars, words, lines. 基本功能的表示。
方法:calculate 基本功能的实现方法。
switch(arr[0]) 对功能进行分类并打印输出结果。
代码
菜单(主代码,启动程序)
package my10;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
while (true){
System.out.println("$$$$$$$$$$$$$$$$$$$");
System.out.println("1: 字符数、词数、行数");
System.out.println(" 输入命令:");
Scanner input=new Scanner(System.in);
String m=input.nextLine();
String arr[]=m.split("\\s");
try{
switch(arr[0]){
case"1":Counter.counter(); break;
}
}
catch (FileNotFoundException e) {
System.out.println("\n找不到文件");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
运算(逻辑函数代码)
package my10;
import java.io.*;
import java.util.Scanner;
public class Counter {
public static void counter( ) throws Exception {
Scanner input = new Scanner(System.in);
System.out.println(" 输入路径:");
String path = input.next();
File file = new File(path);
FileReader reader = new FileReader(file);
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++;
}
System.out.println("字符数 "+countChar);
System.out.println("词数"+countword );
System.out.println("行数 "+countline);
}
}
运行结果





遇到的困难及解决方法
1.对java不太熟悉,需要查找资料,并且最后做出来的功能也只有基础功能。
2.起初用switch(arr[0]),出现报错
Cannot switch on a value of type String for source level below 1.7.
Only convertible int values or enum constants are permitted
百度后才知道只有1.7以上才支持String,而我则是1.6
3.代码打完后运行时出现 Could not find the main class,不清楚什么原因,百度后也没解决,最后换了一个编译器才成功
总结
开学的第一个作业,不算很难,但任然做的很辛苦,还得上网查找,找同学帮助,暴露了对java的不熟悉,希望能再慢慢学习,进步。
也是第一次写博客。
java实现wc.exe的更多相关文章
- 小白のjava实现wc.exe功能
GitHub地址 项目完成情况 基本功能列表(已实现) wc.exe -c file.c //返回文件 file.c 的字符数 wc.exe -w file.c //返回文件 file. ...
- 软工作业No.1。Java实现WC.exe
网址:https://github.com/a249970271/WC WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有w ...
- JAVA实现WC.exe功能
项目要求 实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他扩展功能,并能够快速地处理多个文件. 具体功能要求: 程序处理用户需求的模式为: wc.exe [paramet ...
- Java 实现 WC.exe
Github:https://github.com/YJOED/Code/tree/master/WC/src 一.题目:实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他 ...
- 软件工程:Java实现WC.exe基本功能
项目相关要求 GitHub地址:https://github.com/3216004716/WC 实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他扩展功能,并能够快速地处 ...
- 软工作业1—java实现wc.exe
github项目地址 https://github.com/liyizhu/wc.exe WC 项目要求 基本功能列表: wc.exe -c file.c //返回文件 file.c 的字符数 ...
- 软件工程实践一 —— java之wc.exe
SoftwareEngineering-wc github项目地址:https://github.com/CuiLam/SoftwareEngineering-wc 项目相关要求 实现一个统计程序 ...
- 软工作业1:wc.exe项目开发(java)
Github地址:https://github.com/Zzhaomin/learngit 项目相关要求 : wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个 ...
- WC.exe(Java实现)
一.GitHub项目地址:https://github.com/nullcjm/mypage 二.项目相关要求: wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写 ...
随机推荐
- java 中拿项目路径
public class ItemPathInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHan ...
- 使用发射将JavaBean转为Map
import java.lang.reflect.Field; private static Map<String, Object> objectToMap(Object obj) thr ...
- spring boot1.0 集成quartz 动态配置定时任务
转载自 https://www.imooc.com/article/36278 一.Quartz简介了解 Quartz Quartz 是一个完全由 Java 编写的开源作业调度框架,为在 Java 应 ...
- php操作redis数据库方法总结
一.安装php_redis扩展,用以操作redis http://pecl.php.net/package/redis 选择自已系统php版本对应的扩展. 二.redis连接与验证 <?php ...
- docker 删除所有none的镜像
docker images|grep none|awk '{print $3}'|xargs docker rmi
- android 7.0 调用系统相机崩溃的解决方案(非谷歌官方推荐)
解决方案: 1.(推荐)7.0之后你的app就算有权限,给出一个URI之后手机也认为你没有权限. 不用修改原有代码,在Application的oncreate方法中:(或者直接放在调用相机的activ ...
- lodash 判断一个数据是否包含另一个数组
if (_.intersection(v.ids, value).length == value.length) { this.groupListExtData.push(v.names); } ...
- 【aardio】如何让edit控件只能输入数字、小数点及 - 号
import win.ui; /*DSG{{*/ var winform = win.form(parent=...; text="aardio Form";right=349;b ...
- HTML5新增表单验证
HTML5新增属性: 属性 描述 placeholder 提供一种提示,输入域为空时显示,获得焦点输入内容后消失 required 规定输入域不能为空 pattern 规定验证input域的模式(正则 ...
- windows 上安装冷门python模块
最近在逼乎看到 笑虎大大 的python 撸代码学知识专栏..就下载他的Pspider 框架 安装了一下,准备耍耍. 由于是在Windows下的pycharm 有个 pybloom_live 模块 老 ...