From 01dd55cd08098cfbdc1cda8d99bbe4793f5a5c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8D=9A=E6=96=87?= <15549487+FX_YBW@user.noreply.gitee.com> Date: Wed, 24 Sep 2025 12:20:25 +0800 Subject: [PATCH] test1 --- .idea/misc.xml | 3 -- src/Main.java | 5 -- src/mathpuzzle/Main.java | 9 ++++ .../controller/StartController.java | 54 +++++++++++++++++++ src/mathpuzzle/entity/User.java | 25 +++++++++ src/mathpuzzle/system/LogSystem.java | 50 +++++++++++++++++ 6 files changed, 138 insertions(+), 8 deletions(-) delete mode 100644 src/Main.java create mode 100644 src/mathpuzzle/Main.java create mode 100644 src/mathpuzzle/controller/StartController.java create mode 100644 src/mathpuzzle/entity/User.java create mode 100644 src/mathpuzzle/system/LogSystem.java diff --git a/.idea/misc.xml b/.idea/misc.xml index f64831b..07115cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - diff --git a/src/Main.java b/src/Main.java deleted file mode 100644 index 2d15bb7..0000000 --- a/src/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/src/mathpuzzle/Main.java b/src/mathpuzzle/Main.java new file mode 100644 index 0000000..d08a083 --- /dev/null +++ b/src/mathpuzzle/Main.java @@ -0,0 +1,9 @@ +package mathpuzzle; +import mathpuzzle.controller.StartController; + +public class Main { + public static void main(String[] args) { + StartController startController = new StartController(); + startController.start(); + } +} diff --git a/src/mathpuzzle/controller/StartController.java b/src/mathpuzzle/controller/StartController.java new file mode 100644 index 0000000..e9a0b09 --- /dev/null +++ b/src/mathpuzzle/controller/StartController.java @@ -0,0 +1,54 @@ +package mathpuzzle.controller; +import java.util.Scanner; +import mathpuzzle.entity.User; +import mathpuzzle.system.LogSystem; + + +public class StartController { + public void start() { + LogSystem logSystem = new LogSystem(); + logSystem.userHashMapInit(); + Scanner scanner = new Scanner(System.in); + while (true) { + User user = logSystem.login(); + if (user == null) { + continue; + } + while (true) { + System.out.println("准备生成 " + user.getLevel() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); + String input = scanner.nextLine(); + try { + if ("-1".equals(input)) { + System.out.println("退出当前用户"); + break; + } + int count = Integer.parseInt(input); + if (count < 10 || count > 30) { + System.out.println("题目数量必须在10-30之间!"); + continue; + } + //handleQuestionGeneration(user, count); + } catch (NumberFormatException e) { + handleLevelSwitch(user, input); + } + + + } + + } + } + private void handleLevelSwitch(User user, String input) { + if (input.startsWith("切换为")) { + String newLevel = input.substring(3); + if ("小学".equals(newLevel) || "初中".equals(newLevel) || "高中".equals(newLevel)) { + user.setLevel(newLevel); + } else { + System.out.println("请输入小学、初中和高中三个选项中的一个"); + } + } else { + System.out.println("无效输入。请输入题目数量或'切换为 XX'指令。"); + + + } + } +} diff --git a/src/mathpuzzle/entity/User.java b/src/mathpuzzle/entity/User.java new file mode 100644 index 0000000..44f23e8 --- /dev/null +++ b/src/mathpuzzle/entity/User.java @@ -0,0 +1,25 @@ +package mathpuzzle.entity; + +public class User { + private String name; + private String password; + private String level; + public User(String name, String password, String level) { + this.name = name; + this.password = password; + this.level = level; + } + public String getName() { + return name; + } + public String getPassword() { + return password; + } + public String getLevel() { + return level; + } + + public void setLevel(String newLevel) { + level = newLevel; + } +} diff --git a/src/mathpuzzle/system/LogSystem.java b/src/mathpuzzle/system/LogSystem.java new file mode 100644 index 0000000..86f2a83 --- /dev/null +++ b/src/mathpuzzle/system/LogSystem.java @@ -0,0 +1,50 @@ +package mathpuzzle.system; +import mathpuzzle.entity.User; +import java.util.HashMap; +import java.util.Scanner; + +public class LogSystem { + private HashMap userHashMap = new HashMap(); + public void userHashMapInit() { + // 小学 + userHashMap.put("张三1", new User("张三 1", "123", "小学")); + userHashMap.put("张三2", new User("张三 2", "123", "小学")); + userHashMap.put("张三3", new User("张三 3", "123", "小学")); + // 初中 + userHashMap.put("李四1", new User("李四 1", "123", "初中")); + userHashMap.put("李四2", new User("李四 2", "123", "初中")); + userHashMap.put("李四3", new User("李四 3", "123", "初中")); + // 高中 + userHashMap.put("王五1", new User("王五 1", "123", "高中")); + userHashMap.put("王五2", new User("王五 2", "123", "高中")); + userHashMap.put("王五3", new User("王五 3", "123", "高中")); + } + + public User login() { + System.out.println("请输入用户名和密码,两者之间用空格隔开"); + while(true) { + Scanner scanner = new Scanner(System.in); + String[] info = scanner.nextLine().split(" "); + if(info.length != 2) { + System.out.println("请输入正确格式"); + continue; + } else { + String name = info[0]; + String password = info[1]; + User user = userHashMap.get(name); + if (user == null) { + System.out.println("输入正确的用户名、密码"); + continue; + } + else if (!user.getPassword().equals(password)) { + System.out.println("输入正确的用户名、密码"); + continue; + } + else { + System.out.println("登录成功"); + return user; + } + } + } + } +}