From cd7dc30e92d61ed3d60c4604f79a27139deedda0 Mon Sep 17 00:00:00 2001 From: Teptao <1650163832@qq.com> Date: Thu, 25 Sep 2025 17:18:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4IN=5FGENERATE=5FCOUNT,MAX=5FG?= =?UTF-8?q?ENERATE=5FCOUNT=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A810?= =?UTF-8?q?=EF=BC=8C30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Application.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Application.java b/src/Application.java index 4937bb9..eabd0a7 100644 --- a/src/Application.java +++ b/src/Application.java @@ -20,8 +20,6 @@ public class Application { // 用于解析“切换为XX”命令的正则表达式 private static final Pattern SWITCH_COMMAND_PATTERN = Pattern.compile("^切换为(小学|初中|高中)$"); - private static final int MIN_GENERATE_COUNT = 10; - private static final int MAX_GENERATE_COUNT = 30; public Application() { this.scanner = new Scanner(System.in, "UTF-8"); @@ -71,7 +69,7 @@ public class Application { Optional userOptional = authService.login(credentials[0], credentials[1]); if (userOptional.isPresent()) { sessionManager.startSession(userOptional.get()); - System.out.println("登录成功!欢迎您," + userOptional.get().getUsername() + "。"); + System.out.println("登录成功!欢迎您," + credentials[0] + "。"); } else { System.out.println("用户名或密码错误,请重试。"); } @@ -83,22 +81,21 @@ public class Application { private void handleLoggedInState() throws IOException { String currentLevelName = sessionManager.getCurrentLevelName(); System.out.printf( - "当前选择为%s出题。请输入生成题目数量(%d-%d),或输入 '切换为XX',或输入 '-1' 退出登录:%n", - currentLevelName, MIN_GENERATE_COUNT, MAX_GENERATE_COUNT); + "当前选择为%s出题。请输入生成题目数量(10-30),或输入 '切换为XX',或输入 '-1' 退出登录:%n", + currentLevelName); String input = scanner.nextLine().trim(); - if ("-1".equals(input)) { handleLogout(); } else if (isSwitchCommand(input)) { handleSwitchLevel(input); } else if (isNumeric(input)) { int count = Integer.parseInt(input); - validateGenerateCount(count); - handleGenerateProblems(count); + if(validateGenerateCount(count)) { + handleGenerateProblems(count); + } } else { - - + System.out.println("无效的选项,请重新输入"); } } @@ -150,10 +147,12 @@ public class Application { return str != null && str.matches("-?\\d+"); } - private void validateGenerateCount(int count) { - if (count < MIN_GENERATE_COUNT || count > MAX_GENERATE_COUNT) { + private boolean validateGenerateCount(int count) { + if (count < 10 || count > 30) { System.out.println("生成数量必须在10到30之间。"); + return false; } + return true; } public static void main(String[] args) throws IOException {