第一次个人编程作业
github连接
这个作业属于哪个课程 | 工程概论 |
---|---|
这个作业要求在哪里 | 作业的要求 |
这个作业的目标 | 初步学会完整开发一个项目 |
需求
题目:论文查重
描述如下:
设计一个论文查重算法,给出一个原文文件和一个在这份原文上经过了增删改的抄袭版论文的文件,在答案文件中输出其重复率。
- 原文示例:今天是星期天,天气晴,今天晚上我要去看电影。
- 抄袭版示例:今天是周天,天气晴朗,我晚上要去看电影。
要求输入输出采用文件输入输出,规范如下:
- 从命令行参数给出:论文原文的文件的绝对路径。
- 从命令行参数给出:抄袭版论文的文件的绝对路径。
- 从命令行参数给出:输出的答案文件的绝对路径。
我们提供一份样例,课堂上下发,上传到班级群,使用方法是:orig.txt是原文,其他orig_add.txt等均为抄袭版论文。
注意:答案文件中输出的答案为浮点型,精确到小数点后两位
一、PSP表格
*PSP2.1* | *Personal Software Process Stages* | *预估耗时(分钟)* | *实际耗时(分钟)* |
---|---|---|---|
Planning | 计划 | 20 | 30 |
· Estimate | · 估计这个任务需要多少时间 | 60 | 70 |
Development | 开发 | 30 | 50 |
· Analysis | · 需求分析 (包括学习新技术) | 30 | 50 |
· Design Spec | · 生成设计文档 | 20 | 30 |
· Design Review | · 设计复审 | 10 | 10 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 | 20 |
· Design | · 具体设计 | 10 | 10 |
· Coding | · 具体编码 | 60 | 20 |
· Code Review | · 代码复审 | 10 | 10 |
· Test | · 测试(自我测试,修改代码,提交修改) | 10 | 10 |
Reporting | 报告 | 20 | 20 |
· Test Repor | · 测试报告 | 10 | 10 |
· Size Measurement | · 计算工作量 | 10 | 10 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 20 | 20 |
· 合计 | 330 | 370 |
二.异常情况
1.输入的参数不为3个
2.找不到对应文件
三.源代码
package com.example.personalobj;import java.io.*;
import java.util.*;public class PlagiarismChecker {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入原文文件路径:");String originalFilePath = scanner.nextLine();System.out.println("请输入抄袭版文件路径:");String plagiarizedFilePath = scanner.nextLine();System.out.println("请输入输出文件路径:");String outputFilePath = scanner.nextLine();try {String originalText = readFile(originalFilePath);String plagiarizedText = readFile(plagiarizedFilePath);double similarity = calculateSimilarity(originalText, plagiarizedText);writeResult(outputFilePath, similarity);} catch (IOException e) {e.printStackTrace();}}private static String readFile(String filePath) throws IOException {StringBuilder content = new StringBuilder();try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {String line;while ((line = reader.readLine()) != null) {content.append(line).append("\n");}}return content.toString();}private static double calculateSimilarity(String text1, String text2) {// 这里简单地比较两份文本的相同词语数量String[] words1 = text1.split("\\s+");String[] words2 = text2.split("\\s+");int commonWords = 0;for (String word1 : words1) {for (String word2 : words2) {if (word1.equalsIgnoreCase(word2)) {commonWords++;break;}}}int totalWords = Math.max(words1.length, words2.length);return (double) commonWords / totalWords;}private static void writeResult(String filePath, double similarity) throws IOException {try (PrintWriter writer = new PrintWriter(filePath)) {writer.println("重复率:" + (similarity * 100) + "%");}}
}
四.测试
五.开发环境
idea-2022.2.2