• 202103226编程作业


    这个作业属于哪个课程 [https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/]
    作业目标 [https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879]
    作业要求 码云的使用,和wordcount
    参考文献 [https://blog.csdn.net/p445098355/article/details/104766195]

    psp表格

    PSP2.1 Personal Software Process Stage 预估耗时(分钟) 实际耗时(分钟)
    Planning 计划 15 20
    Estimate 估计这个任务需要多少时间 15 20
    Development 开发 395 498
    Analysis 需求分析 60 88
    Design Spec 生成设计文档 20 15
    Design Review 设计复审 10 10
    Coding Standard 代码规范 15 25
    Design 具体设计 60 40
    Coding 具体编码 180 220
    Code Review 代码复审 10 10
    Test 测试 40 80
    Reporting 报告 60 90
    Test Report 测试报告 20 40
    Size Measurement 计算工作量 10 10
    Postmortem & Process Improvement Plan 事后总结, 并提出过程改进计划 30 40
    合计 940 1206

    解题思路描述
    首先我采用的方法是一个字符一个字符的读取文件内容,这样可以更加便捷的做出判断。将文件每行的内容采用分割法,以非字母、数字的分割符将其分割保存在数组中,在对每个划分后的词进行判断是否为有效单词可以统计文件单词的总数。用replaceAll("s*","")方法可以统计文件的有效行数。词频的统计采用在csdn查找到的Map<String,Integer>的排序方法。

    函数设计
    FileIO:
    getReader(String filePath)
    readFile(String filePath)
    writeToFile(String filePath, String str)
    DoWordCount:
    countChars(String filePath)
    countWords(ArrayList<String> lines)
    countLines(ArrayList<String> lines)
    sortWords(ArrayList<String> lines)
    printTop10(List<Map.Entry<String, Integer>> maplist)
    isValidWord(char[] word)
    isAlpha(int temp)
    其运行结果

    主要代码
    单词分割,统计单词总数

    有效行统计

    用空字符代替空白符

    统计单词出现次数并排序

    单元测试
    public void countChars() {
    String inFile = "C:\Users\CG\IdeaProjects\WordCount\src\input1.txt";
    int characters=0;
    try {
    characters=DoWordCount.countChars(inFile);
    assertEquals(44, characters);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

  • 相关阅读:
    python_异常处理
    python_类与对象
    函数
    字符串(查找,替换,分割)
    容器类型的数据
    条件语句
    关于WinSock编程的多线程控制
    利用Delphi编写Socket通信程序
    SQL Server数据库开发的二十一条军规
    SQL Server中的日期格式化
  • 原文地址:https://www.cnblogs.com/chenguohhw/p/14610155.html
Copyright © 2020-2023  润新知