• 202103226-1 编程作业


    这个作业属于哪个课程 软工-2018级计科2班
    这个作业要求在哪里 202103226-1 编程作业
    这个作业的目标 学习软件开发过程及gitee使用
    学号 20188418

    1.Gitee项目地址

    Gitee项目地址

    2.PSP表格

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

    3.解题思路描述

    1、将input.txt中的内容读取到内存,然后进行数据过滤,具体为判断是不是Ascii值,统计Ascii字符的数量,把非数字字母的符号都替换成空格(对结果没影响)。

    2、将过滤后的数据存到treemap中,用正则表达式判断是不是英文,然后存到treemap中,其中key值为单词,value值为数量。

    3、将treemap中的单词依据value值进行排序。遍历treemap,找到最大的value值对应的key,存到Lis<>集合中,同时从treemap中移除该项,然后继续遍历,直到 Lis<>中有十个值为止。

    4、将Lisa<>中的值输出到output.txt中。

    4.代码规范制定链接

    制定的代码规范

    5.计算模块接口的设计与实现过程

    我写了三个方法,所有的功能都通过这三个方法实现,我将这三个方法封装为Lib类中,在主类中通过实例化Lib对象,调用其中的方法。

    Lib类

      1)Input()方法
      public static String Input(String path1,String path2) throws Exception {
    		int i,number=0;
    		char temp;
    		File f=new File(path1);
    		InputStream input=null;
    		input=new FileInputStream(f);
    		StringBuffer buf=new StringBuffer();
    		long len=f.length();
    		for(i=0;i<len;i++)
    		{
    			temp=(char)input.read();
    			if(temp<=127)
    			{
    				number++;
    				if(temp == '
    '||temp=='
    ')
    				{
    					 temp = ' ';
    				}
    				else if(temp>=32&&temp<=47||
    						temp>=58&&temp<=63||
    						temp>=91&&temp<=96||
    						temp>=123&&temp<=127
    						)
    				{
    					temp=' ';
    				}
    				//System.out.print((char)input.read());
    				buf.append(temp);
    			}
                                else{
                                        buf.append(' ');
                                }
    		}
    		File fl=new File(path2);
    		Writer out=null;
    		out=new FileWriter(fl);
    		out.write("characters :"+String.valueOf(number)+"
    ");
    		out.close();
    		return buf.toString();
    	}
    input的方法实现数据的过滤,并将统计的字符输出的output.txt中
    
    2)Corecode()方法
    public static List<String> Corecode(String path1,String path2) throws Exception {
    		String buf=path1;
    		int i,c=0,d;
    		Map<String,Integer>map=null;
    		map=new TreeMap<String,Integer>();
    		String [] arr = buf.split("\s+");
    		for(i=0;i<arr.length;i++)
    		{
    			if(arr[i].length()>=4)
    			{
    				if(arr[i].substring(0, 3).matches("[a-zA-Z]+"))
    				{
    					c++;
    					if(map.containsKey(arr[i]))
    					{
    						Integer count = map.get(arr[i]);
    						map.put(arr[i],++count);
    					}
    					else {
    						map.put(arr[i],1);//首次则置1
    					}
    				}
    			}
    		}
    		File fl=new File(path2);
    		Writer out=null;
    		out=new FileWriter(fl,true);
    		out.write("words :"+String.valueOf(c)+"
    ");
    		out.close();
    		List<String>list=null;
    		list=new ArrayList<String>();
    		if(c<10)
    			d=c;
    		else
    			d=10;
    		for(i=0;i<d;i++)
    		{
    			String maxw="";
    			Integer maxn=0;
    			for(String w : map.keySet()) {
    				if(map.get(w)>maxn) {
    					maxn=map.get(w);
    					maxw=w;
    				}
    			}
    			list.add(maxw+": "+maxn);
    			map.remove(maxw, maxn);
    		}
    		return list;
    	}
    该方法用来实现单词的统计,把单词按数量的大小存到Lis中。
    
    3)Line()方法
    public static int Line(String path) throws Exception {
    		File f=new File(path);
    		if(f.exists()){
    		    FileReader fr = new FileReader(f);
    		    LineNumberReader ln = new LineNumberReader(fr);
    		    int line = 0;
    	            while (ln.readLine() != null){
    	            	line++;
    	            }
    	            ln.close();
    	            return line;
    		}else
    		{
    			return 0;
    		}
    	}
    该方法实现统计行数
    

    6.计算模块接口部分的性能改进

    在corecode()方法中,本来是用hashmap存数据的,但是写入到文档中后发现结果混乱,然后就改用了Lis集合存数据,然后就解决了。

    7.计算模块部分单元测试展示

    8.异常处理说明

    写代码的过程中主要遇到了找不到文件位置的异常和字符转换错误异常,都比较好解决,由于写的时候一心只想解决问题,所以也没有截图。

    9.心路历程与收获

    这次的编程作业对我来说还是有点难的,首先我有很长一段时间没用Java写代码了,生疏了,我翻了好久的书,还借鉴了一下别人的代码,当然主要是看别人的思路;
    其次,我看着作业要求看的非常迷,起初看不懂要求,不知道要用cmd运行代码,不过学会用cmd运行代码也好;最后,对与git的操作,我还是不懂,以后还得多用。通过这次实验,锻炼了我写代码的能力,和需求分析的能力,希望下次能做的更好。

  • 相关阅读:
    poj2502(最短路)
    poj1511(最小环和)
    uva11090(spfa判负环)
    hdu4370(spfa最短路最小环)
    uva10561(SG)
    uvalive5059(SG)
    uvaliva3905(扫描线)
    scu4445(模拟)
    uvalive3902(树上的最优化 贪心)
    scu4444(完全图最短路)
  • 原文地址:https://www.cnblogs.com/jk-liulei/p/14608543.html
Copyright © 2020-2023  润新知