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

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879
    这个作业的目标 软件工程>

    码云仓库地址:
    https://gitee.com/xzyll/project-java

    思考过程:
    首先看到题目, 脑瓜子时懵懵的 , 一时之间看不明白题目,很多东西没有看懂,后来向别人请教 ,清楚了用HashMap,单词-数量;这样单词数量就好解决了。而且在大一的时候我们就做过类似的题目时在一行英文中找出其中“s”出现的次数,其作业地址https://www.cnblogs.com/liualiu/p/11600496.html,顿时有了思路。
    代码规范地址:https://gitee.com/xzyll/project-java/blob/master/20188484徐子溢/src/ codestyle.md

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

    WordCount
    词频计数的核心方法,利用读取本地input.txt文件中的进行计数

    public class WordCount {
        private static final File ROOT_File =new File("E:\app\");
        private static int count = 0;
        private static Map<String,Integer> wordCount = new HashMap<>();
    
        public static void main(String [] args) throws Exception{
            String intputFileName =  args[0];
            String outputFileName = args[1];
            File inputFile = new File(ROOT_File,intputFileName);
            File outputFile = new File(ROOT_File,outputFileName);
    
    

    判断是否存在:
    doChek默认变化检测算法通过在变化检测运行中比较绑定属性值的引用来查找差异。

            if(inputFile.exists()){
                doCheck(inputFile);
            }else{
                throw new RuntimeException("error");
            }
            PrintStream stream = new PrintStream(new FileOutputStream(outputFile));
            System.setOut(stream);
            show();
            System.out.println("单词数:"+obtainTotalWords());
            System.out.println("行数:"+count);
            System.out.println("字符数:"+(inputFile.length()));
    

    分析每一行代码

        public  static void doCheck(File inputFile) throws Exception{
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
            String line = null;
            while(null!=(line=br.readLine())){
                incrLine();
                
                analysis(line);
            }
        }
    

    排序
    进行排序 而且记录总单词数

     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 incrLine(){
            // 行数加1
            count++;
        }
    

    得到每一个单词以及次数, 并且记录到Map集合中

    
        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);
                    }
                }
            }
        }
    

    在这里用ascall码值排除中文

        public static boolean isWord(String word){
            for(int i=0;i<word.length();i++){
                if(word.charAt(i)>=97 && word.charAt(i)<=122){
                    continue;
                }else{
                    return false;
                }
            }
            return true;
        }
    }
    

    码云推送命令行

    在本地建立input.txt文件

    输入命令行

    编译之后生成output.txt文件
    运行结果输出

    心路历程与收获
    一开始发布这个这个作业的时候,看到这么多文字,脑袋的确懵懵的,很多东西没有学过自己得去一步步得摸索,像git在大一的时候接触过一点点,但是现在很多都忘记了,虽然自己在班级微信群是不是抱怨几句,但是做完这个作业,自己也学会了很多在课堂没有学到过的东西,自己收获很多,学会很多技术 在以后的工作过也一定用的到
    最后十分感谢曹稳根(根哥)老师帮助我们小组完成此次作业,交了我们很多知识,由衷的感谢。

  • 相关阅读:
    Python容器篇 4 -- 字典
    Python容器篇 3 -- 元组
    Python容器篇 2 -- 列表
    Python容器篇 1 -- 字符串
    Python中的关键字
    SQLI-LABS靶场环境搭建详细流程
    Qt QLineEdit 改变text内容的大小
    linux下QT连接mysql找不到驱动
    apt(rpm) Mysql安装
    const 成员函数
  • 原文地址:https://www.cnblogs.com/liualiu/p/14607393.html
Copyright © 2011-2022 走看看