202103226-1 编程作业

------------恢复内容开始------------

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879
这个作业的目标 学习使用Git和Github,完成词频统计编程
其他参考文献 构建之法

Gitee地址:https://gitee.com/duanfei11/project-java

PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 30 15
• Estimate • 估计这个任务需要多少时间 700 1000
Development 开发 82 100
• Analysis • 需求分析 (包括学习新技术) 10 15
• Design Spec • 生成设计文档 5 8
• Design Review • 设计复审 4 6
• Coding Standard • 代码规范 (为目前的开发制定合适的规范) 3 3
• Design • 具体设计 10 20
• Coding • 具体编码 480 720
• Code Review • 代码复审 7 14
• Test • 测试(自我测试,修改代码,提交修改) 31 33
Reporting 报告 9 9
• Test Repor • 测试报告 3 3
• Size Measurement • 计算工作量 2 2
• Postmortem & Process Improvement Plan • 事后总结, 并提出过程改进计划 3 5
合计 1376 2053

3.解题思路
(1)采用java语言实现
(2)解决文件输入输出的问题
4.关键代码
package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/*

  • InputStreamReader(new FileInputStream(绝对文件名))进行文件的读取
  • BufferedReader(文件读取)调用readLine()的方法
    */

public class test {
public static void main(String[] args) throws Exception {
// 统计一个文件的字符数,单词数,行数
Scanner input = new Scanner(System.in);
int countChar = 0;
int countword = 0;
int countline = 0;
InputStreamReader isr = new InputStreamReader(new FileInputStream(path));//用来读取文件中的数据
BufferedReader br = new BufferedReader(isr);//使用缓冲区,可以使用缓冲区的read(),readLine()方法;
/*readLine每次读取一行,read()读取整个文件,是生成文件内容最直接的方式,如果连续面向行的处理则是没有必要的
可直接综合为
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
*/
while(br.read()!=-1)//read()=-1代表数据读取完毕
{
String s = br.readLine();
countChar += s.length();//字符个数就是字符长度
countword += s.split(" ").length;//split() 方法用于把一个字符串分割成字符串数组,字符串数组的长度,就是单词个数
countline++;//因为是按行读取,所以每次增加一即可计算出行的数目
}
isr.close();//关闭文件
System.out.println("characters "+ ":"+countChar);
System.out.println("words "+":"+countword );
System.out.println("lines"+":"+countline);
}
}
测试结果:
总结:这次作业也太难了,基本不会怎么去做,不过初步学习了如何使用github,希望通过以后的学习能更加深入了解github,在以后的作业中能够做的更快。

原文地址:https://www.cnblogs.com/duannaud/p/14612029.html