diff --git a/doc/个人项目使用大模型后人工修改代码一览表.docx b/doc/个人项目使用大模型后人工修改代码一览表.docx new file mode 100644 index 0000000..3227cf2 Binary files /dev/null and b/doc/个人项目使用大模型后人工修改代码一览表.docx differ diff --git a/src/AuthenticationManager.class b/src/AuthenticationManager.class new file mode 100644 index 0000000..e252e1d Binary files /dev/null and b/src/AuthenticationManager.class differ diff --git a/src/FileManager.class b/src/FileManager.class new file mode 100644 index 0000000..3f9e601 Binary files /dev/null and b/src/FileManager.class differ diff --git a/src/JuniorQuestionGenerator.class b/src/JuniorQuestionGenerator.class new file mode 100644 index 0000000..ef5a474 Binary files /dev/null and b/src/JuniorQuestionGenerator.class differ diff --git a/src/MathExamGenerator.class b/src/MathExamGenerator.class new file mode 100644 index 0000000..2531c09 Binary files /dev/null and b/src/MathExamGenerator.class differ diff --git a/src/MathExamGenerator.java b/src/MathExamGenerator.java new file mode 100644 index 0000000..bed486e --- /dev/null +++ b/src/MathExamGenerator.java @@ -0,0 +1,396 @@ +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Pattern; + +// û +class User { + private String username; + private String password; + private String type; + + public User(String username, String password, String type) { + this.username = username; + this.password = password; + this.type = type; + } + + public String getUsername() { return username; } + public String getPassword() { return password; } + public String getType() { return type; } +} + +// Ŀ +abstract class QuestionGenerator { + protected Random random = new Random(); + + public abstract String generateQuestion(); + + protected int generateNumber() { + return random.nextInt(100) + 1; + } + + protected String generateOperator() { + String[] operators = {"+", "-", "*", "/"}; + return operators[random.nextInt(operators.length)]; + } +} + +// СѧĿ +class PrimaryQuestionGenerator extends QuestionGenerator { + @Override + public String generateQuestion() { + int operandCount = random.nextInt(3) + 2; + StringBuilder question = new StringBuilder(); + + boolean hasParentheses = random.nextBoolean() && operandCount >= 3; + int parenthesesPosition = random.nextInt(operandCount - 1); + + for (int i = 0; i < operandCount; i++) { + if (hasParentheses && i == parenthesesPosition) { + question.append("("); + } + + question.append(generateNumber()); + + if (hasParentheses && i == parenthesesPosition + 1) { + question.append(")"); + } + + if (i < operandCount - 1) { + question.append(" ").append(generateOperator()).append(" "); + } + } + + return question.toString(); + } +} + +// Ŀ +class JuniorQuestionGenerator extends QuestionGenerator { + @Override + public String generateQuestion() { + int operandCount = random.nextInt(3) + 2; + StringBuilder question = new StringBuilder(); + + boolean hasSpecialOperator = false; + int specialOperatorPosition = random.nextInt(operandCount); + + for (int i = 0; i < operandCount; i++) { + if (i == specialOperatorPosition && !hasSpecialOperator) { + if (random.nextBoolean()) { + question.append(generateNumber()).append("^2"); // Ϊ^2ʾƽ + hasSpecialOperator = true; + } else { + question.append("").append(generateNumber()); + hasSpecialOperator = true; + } + } else { + question.append(generateNumber()); + } + + if (i < operandCount - 1) { + question.append(" ").append(generateOperator()).append(" "); + } + } + + if (!hasSpecialOperator) { + if (random.nextBoolean()) { + question.append(" ").append(generateOperator()).append(" ").append(generateNumber()).append("^2"); + } else { + question.append(" ").append(generateOperator()).append(" ").append("").append(generateNumber()); + } + } + + return question.toString(); + } +} + +// Ŀ +class SeniorQuestionGenerator extends QuestionGenerator { + private final String[] trigFunctions = {"sin", "cos", "tan"}; + + @Override + public String generateQuestion() { + int operandCount = random.nextInt(3) + 2; + StringBuilder question = new StringBuilder(); + + boolean hasTrigFunction = false; + int trigPosition = random.nextInt(operandCount); + + for (int i = 0; i < operandCount; i++) { + if (i == trigPosition && !hasTrigFunction) { + String trigFunction = trigFunctions[random.nextInt(trigFunctions.length)]; + question.append(trigFunction).append("(").append(generateNumber()).append(")"); + hasTrigFunction = true; + } else { + question.append(generateNumber()); + } + + if (i < operandCount - 1) { + question.append(" ").append(generateOperator()).append(" "); + } + } + + if (!hasTrigFunction) { + String trigFunction = trigFunctions[random.nextInt(trigFunctions.length)]; + question.append(" ").append(generateOperator()).append(" ").append(trigFunction).append("(").append(generateNumber()).append(")"); + } + + return question.toString(); + } +} + +// û֤ +class AuthenticationManager { + private Map users; + + public AuthenticationManager() { + users = new HashMap(); + initializeUsers(); + } + + private void initializeUsers() { + // Сѧ˻ + users.put("1", new User("1", "123", "Сѧ")); + users.put("2", new User("2", "123", "Сѧ")); + users.put("3", new User("3", "123", "Сѧ")); + + // ˻ + users.put("1", new User("1", "123", "")); + users.put("2", new User("2", "123", "")); + users.put("3", new User("3", "123", "")); + + // ˻ + users.put("1", new User("1", "123", "")); + users.put("2", new User("2", "123", "")); + users.put("3", new User("3", "123", "")); + } + + public User authenticate(String username, String password) { + User user = users.get(username); + if (user != null && user.getPassword().equals(password)) { + return user; + } + return null; + } +} + +// ļ +class FileManager { + private static final String BASE_DIR = "exams"; + + public FileManager() { + File baseDir = new File(BASE_DIR); + if (!baseDir.exists()) { + baseDir.mkdir(); + } + } + + public String generateFilename() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); + return sdf.format(new Date()) + ".txt"; + } + + public String getUserDir(String username) { + return BASE_DIR + File.separator + username; + } + + public void saveQuestions(String username, List questions) throws IOException { + String userDir = getUserDir(username); + File dir = new File(userDir); + if (!dir.exists()) { + dir.mkdir(); + } + + String filename = generateFilename(); + String filepath = userDir + File.separator + filename; + + // ʹGBK뱣ļ + try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filepath), "GBK"))) { + for (int i = 0; i < questions.size(); i++) { + writer.println((i + 1) + ". " + questions.get(i)); + if (i < questions.size() - 1) { + writer.println(); + } + } + } + + System.out.println("Ŀѱ浽: " + filepath); + } + + public boolean checkDuplicate(String username, String question) { + String userDir = getUserDir(username); + File dir = new File(userDir); + + if (!dir.exists()) { + return false; + } + + File[] files = dir.listFiles(); + if (files == null) { + return false; + } + + for (File file : files) { + try (Scanner scanner = new Scanner(file, "GBK")) { + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.contains(question)) { + return true; + } + } + } catch (IOException e) { + // Զȡ + } + } + + return false; + } +} + +// +public class MathExamGenerator { + private AuthenticationManager authManager; + private FileManager fileManager; + private User currentUser; + private String currentType; + private Scanner scanner; + + public MathExamGenerator() { + authManager = new AuthenticationManager(); + fileManager = new FileManager(); + scanner = new Scanner(System.in); + } + + public void start() { + System.out.println("===== СѧѧԶɳ ====="); + + while (true) { + if (currentUser == null) { + login(); + } else { + generateExam(); + } + } + } + + private void login() { + System.out.println("û루ÿո:"); + String input = scanner.nextLine().trim(); + + if (input.equalsIgnoreCase("exit")) { + System.exit(0); + } + + String[] parts = input.split(" "); + if (parts.length != 2) { + System.out.println("ȷû"); + return; + } + + String username = parts[0]; + String password = parts[1]; + + currentUser = authManager.authenticate(username, password); + if (currentUser != null) { + currentType = currentUser.getType(); + System.out.println("ǰѡΪ" + currentType + ""); + } else { + System.out.println("ȷû"); + } + } + + private void generateExam() { + System.out.println("׼" + currentType + "ѧĿĿ-1˳ǰûµ¼:"); + + String input = scanner.nextLine().trim(); + + if (input.equals("-1")) { + currentUser = null; + return; + } + + if (input.startsWith("лΪ")) { + handleTypeSwitch(input); + return; + } + + int questionCount; + try { + questionCount = Integer.parseInt(input); + } catch (NumberFormatException e) { + System.out.println("Ч֣10-30-1˳"); + return; + } + + if (questionCount != -1 && (questionCount < 10 || questionCount > 30)) { + System.out.println("ĿӦ10-30֮"); + return; + } + + List questions = generateQuestions(questionCount); + + try { + fileManager.saveQuestions(currentUser.getUsername(), questions); + } catch (IOException e) { + System.out.println("ļʱ: " + e.getMessage()); + } + } + + private void handleTypeSwitch(String input) { + Pattern pattern = Pattern.compile("лΪ(Сѧ||)"); + java.util.regex.Matcher matcher = pattern.matcher(input); + + if (matcher.matches()) { + currentType = matcher.group(1); + System.out.println("׼" + currentType + "ѧĿĿ"); + } else { + System.out.println("Сѧк͸ѡеһ"); + } + } + + private List generateQuestions(int count) { + QuestionGenerator generator = getQuestionGenerator(); + List questions = new ArrayList(); + Set generatedQuestions = new HashSet(); + + int maxAttempts = count * 10; + int attempts = 0; + + while (questions.size() < count && attempts < maxAttempts) { + String question = generator.generateQuestion(); + + if (!generatedQuestions.contains(question)) { + if (!fileManager.checkDuplicate(currentUser.getUsername(), question)) { + questions.add(question); + generatedQuestions.add(question); + } + } + attempts++; + } + + if (questions.size() < count) { + System.out.println("棺Ŀظֻ " + questions.size() + " Ŀ"); + } + + return questions; + } + + private QuestionGenerator getQuestionGenerator() { + if ("Сѧ".equals(currentType)) { + return new PrimaryQuestionGenerator(); + } else if ("".equals(currentType)) { + return new JuniorQuestionGenerator(); + } else if ("".equals(currentType)) { + return new SeniorQuestionGenerator(); + } else { + return new PrimaryQuestionGenerator(); + } + } + + public static void main(String[] args) { + MathExamGenerator generator = new MathExamGenerator(); + generator.start(); + } +} \ No newline at end of file diff --git a/src/PrimaryQuestionGenerator.class b/src/PrimaryQuestionGenerator.class new file mode 100644 index 0000000..7cf3edc Binary files /dev/null and b/src/PrimaryQuestionGenerator.class differ diff --git a/src/QuestionGenerator.class b/src/QuestionGenerator.class new file mode 100644 index 0000000..9baa1e9 Binary files /dev/null and b/src/QuestionGenerator.class differ diff --git a/src/SeniorQuestionGenerator.class b/src/SeniorQuestionGenerator.class new file mode 100644 index 0000000..98688e2 Binary files /dev/null and b/src/SeniorQuestionGenerator.class differ diff --git a/src/User.class b/src/User.class new file mode 100644 index 0000000..744daeb Binary files /dev/null and b/src/User.class differ diff --git a/src/exams/张三1/2025-09-27-13-13-52.txt b/src/exams/张三1/2025-09-27-13-13-52.txt new file mode 100644 index 0000000..74575d8 --- /dev/null +++ b/src/exams/张三1/2025-09-27-13-13-52.txt @@ -0,0 +1,21 @@ +1. 71 / 95 + 37 - 82 + +2. 64 / 83 + +3. 50 * 54 / 54 + +4. (27 - 93) - 95 + +5. 20 - (78 * 27) - 38 + +6. 37 * 75 + (50 + 30) + +7. 23 / 1 * 78 + +8. 54 - 25 / 76 + +9. 90 * (79 / 42) + 41 + +10. 78 + 15 * 6 + 96 + +11. 74 + 63 - 97 - 34 diff --git a/src/exams/李四1/2025-09-27-12-54-51.txt b/src/exams/李四1/2025-09-27-12-54-51.txt new file mode 100644 index 0000000..698915d --- /dev/null +++ b/src/exams/李四1/2025-09-27-12-54-51.txt @@ -0,0 +1,21 @@ +1. 87 + 84^2 + +2. 87 * 78 - 10 + +3. 14 * 25 + +4. 37 / 4 / 25 / 19 + +5. 34 / 69^2 * 90 + +6. 56 * 45 + 81^2 * 99 + +7. 59 / 44 / 70 / 47 + +8. 17^2 + 77 - 49 + +9. 48 / 95 * 98 + +10. 47 / 20 + 49 / 34 + +11. 62^2 + 5 diff --git a/src/exams/李四1/2025-09-27-12-55-25.txt b/src/exams/李四1/2025-09-27-12-55-25.txt new file mode 100644 index 0000000..7dd8ed9 --- /dev/null +++ b/src/exams/李四1/2025-09-27-12-55-25.txt @@ -0,0 +1,21 @@ +1. 40 / (46 * 2) * 92 + +2. 93 * 71 + +3. (56 / 61) / 64 + 10 + +4. (34 / 70) / 88 + +5. 18 - 96 - 53 + +6. 88 + 55 + 50 + +7. (42 * 21) * 64 + +8. 41 / 35 + +9. (15 - 29) + 85 + +10. 10 - 8 - 5 / 76 + +11. 72 - 1 * 58 + 92 diff --git a/src/exams/李四2/2025-09-27-12-55-39.txt b/src/exams/李四2/2025-09-27-12-55-39.txt new file mode 100644 index 0000000..ec24670 --- /dev/null +++ b/src/exams/李四2/2025-09-27-12-55-39.txt @@ -0,0 +1,21 @@ +1. 71 * 100 * 96 - 86 + +2. 50 * 86^2 * 71 * 15 + +3. 84 + 95^2 + 66 - 60 + +4. 23 / 32 + 21^2 - 31 + +5. 85 + 93 + 30 + +6. 31 + 58 / 96 + +7. 16 / 13 - 87 + +8. 93 / 92 + +9. 26 / 86 * 85 - 33 + +10. 83 / 95 + 53 * 30 + +11. 95^2 * 60 diff --git a/src/exams/王五1/2025-09-27-13-14-25.txt b/src/exams/王五1/2025-09-27-13-14-25.txt new file mode 100644 index 0000000..53897fd --- /dev/null +++ b/src/exams/王五1/2025-09-27-13-14-25.txt @@ -0,0 +1,21 @@ +1. 55 - 17 * sin(100) + 44 + +2. sin(97) - 23 / 44 + 40 + +3. 62 + tan(16) + 74 - 6 + +4. sin(53) - 31 * 58 / 75 + +5. 52 + cos(93) + +6. 70 - tan(12) + 28 + +7. 55 + tan(7) * 80 + +8. 93 / cos(61) + +9. 89 - tan(75) + +10. 47 + 50 * 72 + sin(25) + +11. tan(50) - 13