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 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写 ...
随机推荐
- 项目总结20:阿里云免费https证书申请
项目总结20:阿里云免费https证书申请 1. 登录阿里云控制台 www.aliyun.com,用账户信息登录 2. 在”产品与服务”搜索SSL,选择SSL证书 3. 点击购买证书 4. 选择” S ...
- ASP.NET Core Web多语言项目
公司效益好了,准备和国外做生意,这个时候就需要多语言了. > 1. 这是一个ASP.NET Core Web多语言项目,主要展示项目的不同: > 2. 第一种:www.xxx.com/en ...
- skynet记录2:模块简介
稍后填坑 bson.so client.so lpeg.so md5.so skynet.so sproto.so gate.so harbor.so logger.so snlua. ...
- IEnumerable对象的Distinct方法重写
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource ...
- V2019 Super DSP3 Odometer Correction Vehicle List
Comparing v2017 Super DSP3 mileage programmer, the newest V2019 Super DSP III adds newer vehicles, i ...
- C51汇编典型代码&一些org-mode技巧
C51汇编典型代码&一些org-mode技巧 文档存放 具体内容可见存放的数据. 下面主要介绍关键代码. ASM 部分 1;; LCD数据发送========================= ...
- node.js生成二维码
var http = require('http'); var qs = require('querystring'); var qrImg = require('qr-image'); var se ...
- 《笨方法学Python》加分题35
sys.exit 用于结束程序 from sys import exit # 进入黄金房间后的逻辑 def gold_room(): print("This room is full of ...
- sort 对多列进行排序
sort -t '\t' -k 3,3 -k 2,2 文件名 # 先对第三列进行排序,然后再对第二列进行排序
- Echarts 在动态HTML报告中的应用
# 参考官网 http://echarts.baidu.com/examples/ <scripts> <!--- echarts examples ---> </scr ...