diff --git a/out/production/TestPaperGenerationSystem/Application.class b/out/production/TestPaperGenerationSystem/Application.class index ed2fc01..0177629 100644 Binary files a/out/production/TestPaperGenerationSystem/Application.class and b/out/production/TestPaperGenerationSystem/Application.class differ diff --git a/out/production/TestPaperGenerationSystem/InvalidInputException.class b/out/production/TestPaperGenerationSystem/InvalidInputException.class deleted file mode 100644 index a9ea193..0000000 Binary files a/out/production/TestPaperGenerationSystem/InvalidInputException.class and /dev/null differ diff --git a/src/Application.java b/src/Application.java index eabd0a7..fa307fb 100644 --- a/src/Application.java +++ b/src/Application.java @@ -108,11 +108,10 @@ public class Application { private void handleSwitchLevel(String input) { Matcher matcher = SWITCH_COMMAND_PATTERN.matcher(input); if (matcher.matches()) { - String levelName = matcher.group(1); - EducationLevel level = EducationLevel.fromLevelName(levelName); + String level = matcher.group(1); if (level != null) { sessionManager.setCurrentGenerator(level); - System.out.println("成功切换到 " + levelName + " 出题模式。"); + System.out.println("成功切换到 " + level + " 出题模式。"); } } } diff --git a/src/EducationLevel.java b/src/EducationLevel.java deleted file mode 100644 index f345a7a..0000000 --- a/src/EducationLevel.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 教育级别枚举。 - * 用于表示用户的默认级别以及题目生成的难度。 - */ -public enum EducationLevel { - PRIMARY("小学"), - MIDDLE("初中"), - HIGH("高中"); - - private final String levelName; - - EducationLevel(String levelName) { - this.levelName = levelName; - } - - /** - * 获取级别的名称。 - * - * @return 级别名称字符串 - */ - public String getLevelName() { - return levelName; - } - - /** - * 根据中称查找对应的枚举实例。 - * - * @param levelName 要查找的名称,例如 "初中" - * @return 匹配的 EducationLevel 实例,若未找到则返回 null - */ - public static EducationLevel fromLevelName(String levelName) { - for (EducationLevel level : values()) { - if (level.getLevelName().equals(levelName)) { - return level; - } - } - return null; - } -} \ No newline at end of file diff --git a/src/InMemoryUserRepository.java b/src/InMemoryUserRepository.java index d6313c3..9e3f5ba 100644 --- a/src/InMemoryUserRepository.java +++ b/src/InMemoryUserRepository.java @@ -13,17 +13,17 @@ public class InMemoryUserRepository implements UserRepository { public InMemoryUserRepository() { // 初始化预定义的9个用户账户 // 小学老师 - userDatabase.put("张三1", new User("张三1", "123", EducationLevel.PRIMARY)); - userDatabase.put("张三2", new User("张三2", "123", EducationLevel.PRIMARY)); - userDatabase.put("张三3", new User("张三3", "123", EducationLevel.PRIMARY)); + userDatabase.put("张三1", new User("张三1", "123", "小学")); + userDatabase.put("张三2", new User("张三2", "123", "小学")); + userDatabase.put("张三3", new User("张三3", "123", "小学")); // 初中老师 - userDatabase.put("李四1", new User("李四1", "123", EducationLevel.MIDDLE)); - userDatabase.put("李四2", new User("李四2", "123", EducationLevel.MIDDLE)); - userDatabase.put("李四3", new User("李四3", "123", EducationLevel.MIDDLE)); + userDatabase.put("李四1", new User("李四1", "123", "初中")); + userDatabase.put("李四2", new User("李四2", "123", "初中")); + userDatabase.put("李四3", new User("李四3", "123", "初中")); // 高中老师 - userDatabase.put("王五1", new User("王五1", "123", EducationLevel.HIGH)); - userDatabase.put("王五2", new User("王五2", "123", EducationLevel.HIGH)); - userDatabase.put("王五3", new User("王五3", "123", EducationLevel.HIGH)); + userDatabase.put("王五1", new User("王五1", "123", "高中")); + userDatabase.put("王五2", new User("王五2", "123", "高中")); + userDatabase.put("王五3", new User("王五3", "123", "高中")); } @Override diff --git a/src/SessionManager.java b/src/SessionManager.java index 7612401..cf490c7 100644 --- a/src/SessionManager.java +++ b/src/SessionManager.java @@ -38,7 +38,7 @@ public final class SessionManager { public void startSession(User user) { this.currentUser = user; // 根据用户的默认级别,初始化对应的题目生成策略 - setGeneratorByDefaultLevel(user.getDefaultLevel()); + setGeneratorByLevel(user.getDefaultLevel()); } /** @@ -66,27 +66,26 @@ public final class SessionManager { * * @param level 新的教育级别 */ - public void setCurrentGenerator(EducationLevel level) { + public void setCurrentGenerator(String level) { if (level == null) { throw new IllegalArgumentException("难度等级不可为空。"); } - setGeneratorByDefaultLevel(level); + setGeneratorByLevel(level); } - private void setGeneratorByDefaultLevel(EducationLevel level) { + private void setGeneratorByLevel(String level) { switch (level) { - case PRIMARY: + case "小学": this.currentGenerator = new ElementaryProblemGenerator(); break; - case MIDDLE: + case "初中": this.currentGenerator = new MiddleSchoolProblemGenerator(); break; - case HIGH: + case "高中": this.currentGenerator = new HighSchoolProblemGenerator(); break; default: - // 理论上不会发生,因为枚举是固定的 - throw new IllegalStateException("错误的难度等级: " + level); + System.out.println("错误的难度等级: " + level); } } diff --git a/src/User.java b/src/User.java index 67025cd..7a1ecb3 100644 --- a/src/User.java +++ b/src/User.java @@ -8,10 +8,10 @@ public class User { private final String username; private final String password; // 注意:在生产系统中应存储哈希值 - private final EducationLevel defaultLevel; + private final String defaultLevel; private final String storagePath; - public User(String username, String password, EducationLevel defaultLevel) { + public User(String username, String password, String defaultLevel) { this.username = username; this.password = password; this.defaultLevel = defaultLevel; @@ -27,7 +27,7 @@ public class User { return password; } - public EducationLevel getDefaultLevel() { + public String getDefaultLevel() { return defaultLevel; }