第二次编程作业

这个作业属于哪个课程 《软件工程》
这个作业要求在哪里 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/xxn520/project-java/tree/master/20188481王毅豪

PSP

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

代码块
判断是否存在:

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

行数加1:

public static void incrLine(){
		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;

仓库连接:

运行截图:

总结:
程序还是有不完善的地方,像那种缩写就检测不出来,所以还有待改进。总的来说,觉得这次编程还有很有难度的,
真心不容易!!!
最后感谢根哥!!!

posted @ 2021-04-01 22:09  加钱灬居士  阅读(83)  评论(0编辑  收藏  举报