zoukankan      html  css  js  c++  java
  • 编程作业

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879
    这个作业要求在哪里 https://www.cnblogs.com/Bowen----/p/14608365.html
    这个作业的目标 学会使用gitee并且完成词频统计编程
    学号 20188462
    其他参考文献 《构建之法》

    gitee网址
    https://gitee.com/Bowen158/project-java

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

    解题思路:
    首先采用的方法是一个字符一个字符的读取文件内容。将文件每行的内容采用分割法,以非字母、数字的分割符将其分割保存在数组中,从而计数。
    分别统计字符数、单词总数、有效行数及各单词出现次数。

    在桌面新建一个input文本如下

    文本是一个英语小故事,在class文件下地址中的cmd中输入java WordCount input.txt output.txt即可出现相应的output文本如下

    单词数为五十
    行数为七
    字符数为482

    即实现简单输出功能

    主要代码:
    总单词数代码实现
    public static long obtainTotalWords(){
    long sum = 0;
    Set<Map.Entry<String, Integer>> entries = wordCount.entrySet();
    for (Map.Entry<String, Integer> entry : entries) {
    sum+=entry.getValue();
    }
    return sum;
    }

    排序代码实现
    public static void show(){
    Set<Map.Entry<String, Integer>> entries = wordCount.entrySet();
    ArrayList<String> words = new ArrayList<>();
    for (Map.Entry<String, Integer> entry : entries) {
    words.add(entry.getValue()+"#"+entry.getKey());
    }
    Collections.sort(words);
    words.forEach(obj->{
    String[] split = obj.split("#");
    String str = split[1]+": "+split[0];`` System.out.println(str); }); }`

    单词计数实现代码
    public static void analysis(String line){
    String [] words = line.split(" ");
    for(int i=0;i<words.length;i++){
    String word = words[i].trim();
    word = word.toLowerCase();
    word = word.contains(",")||word.contains(".")?word.substring(0,word.length()-1):word;
    if(word.length()>=4&&isWord(word.substring(0,4))){
    if(wordCount.containsKey(word)){
    Integer count = wordCount.get(word);
    count++;
    wordCount.put(word,count);
    }else{
    wordCount.put(word,1);
    }
    }
    } }`
    码云fork链接

    心路历程与收获
    这个作业的题目真的是太多了,有六千多个字,读题目我都读了好久,一步步来操作做了好久好久,之前电脑清理了,然后这段时间才把eclipse下回来,太久没写代码,刚开始的时候创建包都创建错了,真的是太难了,走了好多弯路,终于终于才能达到题目要求做出来,还是要多动手,多学习才能够有成就。

  • 相关阅读:
    git add后 有的文件后悔 add了还没有commit 怎么办?
    go mod module declares its path as: gtihub.com/xxx-xx but was required as:xx-xx
    mysql 复合索引(联合索引) a b c的使用
    git 的初始化使用
    Mac 安装 mysql5.7
    Go Modules与GOPROXY 配置
    ZWWL的短信详设
    Linux 查看文件权限命令ls -l 输出信息每列所代表的含义
    ubuntu/deepin 下增加 goland 桌面快捷方式 goland.desktop
    go语言的冒泡 选择 快排 二分 算法实现
  • 原文地址:https://www.cnblogs.com/Bowen----/p/14608365.html
Copyright © 2011-2022 走看看