202103226-1编程作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class1-2018/homework/11877
这个作业的目标 词频统计编程
学号 20188396

项目地址
https://gitee.com/choujiu/project-java/tree/master/

psp表格

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

解题思路描述
主要需要解决的功能读入文件,然后统计字符总数、单词频率,把处理后返回的结果进行拼接,写入到输出文件中去

设计与实现
lib封装类函数文件读入和文件写入和单词频率等,WordCount主函数

统计字符数

 public static int charactersCount(String inputFile) throws IOException {
        /*Reader reader = openInputFile(inputFile);
        Writer writer = new FileWriter(outputFile);
        int num = 0, temp = 0;
        while ((temp = reader.read()) != -1) {
            num++;
        }
        writer.write("characters: " + num + '\n');
        writer.close();
        reader.close();
        return num;*/
        String str = readFile(inputFile);
        characters=str.length();
        return  characters;
    }

统计单词总数

public static int wordsCount(String inputFile, String outputFile) throws IOException {
        Reader reader = openInputFile(inputFile);

        int temp = 0;
        String word = "";
        while ((temp = reader.read()) != -1) {
            while (isValidChar(temp)) {
                word += (char) temp;
                temp = reader.read();
            }
            while (!isValidChar(temp) && temp != -1) {//去除所有空白字符和分隔符
                temp = reader.read();
            }
            char[] chars = word.toCharArray();
            if (isValidWord(chars)) {//如果单词合法,则单词总数+1
                words++;
            }
            word = "" + (char) temp;
        }

        reader.close();
        return words;
    }

总结
这周作业实在是难,从git和github的基本操作开始学习,然后是作业的思路和具体实现方法,在各网站看了n个视频也问了很多大佬才慢慢理解和操作,其中还有很多细节还需要花时间去慢慢消化。

posted @ 2021-04-02 17:01  zxlzxl  阅读(53)  评论(0编辑  收藏  举报