zoukankan      html  css  js  c++  java
  • 2020软件工程第一次个人编程作业

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzu/SE2020/
    这个作业要求在哪里 https://edu.cnblogs.com/campus/fzu/SE2020/homework/11167
    这个作业的目标 对于GitHub各种内容的熟悉,对于json文件的读取以及数据的处理
    学号 031802640

    一、psp表格

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

    二、解题思路

    拿到这个题目后,整体看了一下题目的要求,就是要在各个项目各个用户中统计几个事件的数量。然后看了一眼给的示例数据,发现以前没怎么接触过json,就到网上查找了一些关于json文件的读取的资料,搞了很久发现只能读入一行,这才发现这个文件必须逐行读入json,这个地方就被坑了好久的时间。之后在gradle中导入jackson依赖的时候又出bug,好不容易勉强打完代码,bulid的时候不能导入依赖,后来才发现要在shadowjar里面bulid才能正常运行。

    三、设计实现过程

    主要的核心过程都在初始化的过程中,初始化时通过一个readJsonFile读入文件夹中的json文件,但时间不是很够,目前只能读入一个json文件。。
    然后在getJsonFile中把读取的json文件转化为字符串的形式,通过换行符切割进行逐行读入,把用户,项目,事件的字符串连接在一起放入问题所需的三个不同的map中遍历进行数据统计,然后写入到三个不同的文本中,当输入问题时再从相应文本中读取

    寻找json文件

    public static String getNameFromOneJsonFile(String dictAddress) {
            File directory = new File(dictAddress);
            if (!directory.isDirectory()) {
                throw new RuntimeException('"' + dictAddress + '"' + " input path is not a Directory , please input the right path of the Directory. ^_^...^_^");
            } else {
                //首先将第一层目录扫描一遍
                File[] files = directory.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (files[i].getName().startsWith(".")){
                        continue;
                    }
                    if (files[i].getName().endsWith("json")) {
                        return dictAddress+"\"+ files[i].getName();
                    }
                }
    
            }
            return null;
        }
    }
    

    将json文件读入并转为字符串

    public static String readJsonFile(String fileName) {
            String jsonStr = "";
            try {
                File jsonFile = new File(fileName);
                FileReader fileReader = new FileReader(jsonFile);
                Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
                int ch = 0;
                StringBuffer sb = new StringBuffer();
                while ((ch = reader.read()) != -1) {
                    sb.append((char) ch);
                }
                fileReader.close();
                reader.close();
                jsonStr = sb.toString();
                return jsonStr;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    

    四、单元测试

    五、代码规范

    https://github.com/Franzzi-z/2020-personal-java/blob/master/codestyle.md

    六、总结

    这次实验 ,总的来说还是学到了很多新的东西,但由于时间问题并没有很好解决,看到了很多自己的不足,再今后的课程学习中还要多多努力。

  • 相关阅读:
    Python 正则表达式入门
    使用numpy与matplotlib.pyplot画图
    快乐python 零基础也能P图 —— PIL库
    Jieba库使用和好玩的词云
    python运用turtle 画出汉诺塔搬运过程
    有进度条圆周率计算
    用pythen画五角星
    pytest+allure+requests-接口自动化测试
    pytest---allure测试报告
    自动化测试---pytest
  • 原文地址:https://www.cnblogs.com/franzzi-z/p/13676132.html
Copyright © 2011-2022 走看看