zoukankan      html  css  js  c++  java
  • 第二次编辑作业

    这个作业属于哪个课程 《软件工程》
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-science-class3-2018/homework/11879
    这个作业的目标 学会使用git,git命令,熟练一个程序开发的过程
    参考文献 https://blog.csdn.net/w2462140956/article/details/104965486

    gitee地址

    https://gitee.com/xzhxzh123/xu-zhuohan
    2、PSP表

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

    三、解题思路描述
    一开始看到这个题目的时候感觉比较难,文字描述比较多,因为是第一次做这个类型的题目,所以不知道从哪里开始,仔细看了很久之后,发现其他的都是作业的要求,作业的重点是需求这一模块。然后就去百度上查阅了相关资料,看了前辈们的作业,发现了作业的重点。

    -实现的要求
    统计文件的字符数(对应输出第一行)
    统计文件的单词总数(对应输出第二行),单词:至少以4个英文字母开头,跟上字母数字符号, 单词以分隔符分割,不区分大小写。
    统计文件的有效行数(对应输出第三行):任何包含非空白字符的行,都需要统计。
    统计文件中各单词的出现次数(对应输出接下来10行),最终只输出频率最高的10个。
    主函数

    
    import java.io.;
    import java.util.;
    
    public class WordCount {
    private static final File ROOT_File =new File("D:新建文件夹");
    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);
    
    // 判断是否存在:
    
        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++;
    }
    

    获取总单词数

    
    //总单词数
    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;
    }
    

    统计单词及其出现的个数

    
    // 得到每一个单词以及次数, 并且记录到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);
                }
            }
        }
    }
    
    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;
    }
    

    总结;

    这一次的作业对于我来说,确实是不大容易,感觉尽是一些没有学习过的东西,这就让我很难受。

    对于我这种很少敲c和java的人来说,这道作业着实有了难度。首先主要问题可能还是代码问题,代码使用Java理解并且写出来还是耗费了许多时间的。

  • 相关阅读:
    hdu4347 The Closest M Points(kdtree+stl)
    bzoj1941 [Sdoi2010]Hide and Seek
    bzoj1941 [Sdoi2010]Hide and Seek
    bzoj2648 SJY摆棋子(不带修改的KDtree的学习)
    bzoj2648 SJY摆棋子(不带修改的KDtree的学习)
    bzoj2588 Spoj 10628. Count on a tree
    hdu2665 Kth number(主席树模板)
    hdu2665 Kth number(主席树模板)
    luoguP3168 [CQOI2015]任务查询系统
    12.模板别名以及auto定义返回值
  • 原文地址:https://www.cnblogs.com/xzhxzh/p/14610149.html
Copyright © 2011-2022 走看看