From 19a45b1f99b360b3f1212f8ceb42cf284eb5d3f9 Mon Sep 17 00:00:00 2001 From: smallbailangui Date: Thu, 25 Sep 2025 21:04:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../java/com/mathgenerator/ui/ConsoleUI.java | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 0973627..9c43a51 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ out/ bin/ questions/ generated_papers/ -target/ \ No newline at end of file +target/ +users.json \ No newline at end of file diff --git a/src/main/java/com/mathgenerator/ui/ConsoleUI.java b/src/main/java/com/mathgenerator/ui/ConsoleUI.java index 1b748cd..3788213 100644 --- a/src/main/java/com/mathgenerator/ui/ConsoleUI.java +++ b/src/main/java/com/mathgenerator/ui/ConsoleUI.java @@ -205,21 +205,25 @@ public class ConsoleUI { * @param currentLevel 当前选择的难度级别。 */ private void handleGeneration(User user, Level currentLevel) { - printHeader("生成 " + currentLevel.getChineseName() + " 题目"); - System.out.print("请输入生成题目数量 (10-30,输入 0 返回主菜单): "); - try { - int count = Integer.parseInt(scanner.nextLine().trim()); - if (count == 0) { - System.out.println("已取消生成,返回主菜单。"); - return; - } - if (count >= 10 && count <= 30) { - paperService.createAndSavePaper(user, count, currentLevel); - } else { - System.out.println("输入无效,题目数量必须在 10 到 30 之间。"); + while (true) { + printHeader("生成 " + currentLevel.getChineseName() + " 题目"); + System.out.print("请输入生成题目数量 (10-30,输入 0 返回主菜单): "); + String input = scanner.nextLine().trim(); + try { + int count = Integer.parseInt(input); + if (count == 0) { + System.out.println("已取消生成,返回主菜单。"); + break; // 退出循环,返回主菜单 + } + if (count >= 10 && count <= 30) { + paperService.createAndSavePaper(user, count, currentLevel); + break; // 成功生成,退出循环,返回主菜单 + } else { + System.out.println("无效输入,题目数量必须在 10 到 30 之间。请重新输入。"); + } + } catch (NumberFormatException e) { + System.out.println("无效输入,请输入一个有效的数字。请重新输入。"); } - } catch (NumberFormatException e) { - System.out.println("输入无效,请输入一个有效的数字。"); } } /**