From 232c548d77b3d072a1aad5445bf820f167a55bfc Mon Sep 17 00:00:00 2001 From: peterpan Date: Thu, 25 Sep 2025 08:24:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9F=BA=E6=9C=AC=E7=99=BB=E9=99=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 40 +++++++++++++++++++++++++++++++++++++++ src/auth/AuthService.java | 25 ++++++++++++++++++++++++ src/model/Level.java | 26 +++++++++++++++++++++++++ src/model/User.java | 25 ++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 src/auth/AuthService.java create mode 100644 src/model/Level.java create mode 100644 src/model/User.java diff --git a/src/Main.java b/src/Main.java index e69de29..432a450 100644 --- a/src/Main.java +++ b/src/Main.java @@ -0,0 +1,40 @@ +import auth.AuthService; +import model.Level; +import model.User; + +import java.util.Scanner; + +public class Main { + private static final AuthService.TestPaperService testPaperService = new AuthService.TestPaperService(); + private static User currentUser = null; + private static Level currentLevel = null; + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + while (true) { + if (currentUser == null) { + handleLogin(scanner); + } else { + handleQuestionGeneration(scanner); + } + } + } + + private static void handleLogin(Scanner scanner) { + System.out.println("**********数学试卷生成项目**********"); + System.out.println("请输入用户名和密码,用空格隔开:"); + String[] input = scanner.nextLine().split(" "); + if (input.length == 2) { + authService.login(input[0], input[1]).ifPresentOrElse( + user -> { + currentUser = user; + currentLevel = user.getLevel(); + System.out.printf("当前选择为%s出题%n", currentLevel.getName()); // 登录成功提示 + }, + () -> System.out.println("请输入正确的用户名、密码") // 登录失败提示 + ); + } else { + System.out.println("输入格式不正确,请重新输入。"); + } + } +} \ No newline at end of file diff --git a/src/auth/AuthService.java b/src/auth/AuthService.java new file mode 100644 index 0000000..3c19cf6 --- /dev/null +++ b/src/auth/AuthService.java @@ -0,0 +1,25 @@ +package auth; + +import model.Level; +import model.User; + +import java.util.ArrayList; +import java.util.List; + +public class AuthService { + private final List users; + + public AuthService() { + this.users = new ArrayList<>(); + // 初始化用户账户 + users.add(new User("张三1", "123", Level.ELEMENTARY)); + users.add(new User("张三2", "123", Level.ELEMENTARY)); + users.add(new User("张三3", "123", Level.ELEMENTARY)); + users.add(new User("李四1", "123", Level.JUNIOR_HIGH)); + users.add(new User("李四2", "123", Level.JUNIOR_HIGH)); + users.add(new User("李四3", "123", Level.JUNIOR_HIGH)); + users.add(new User("王五1", "123", Level.SENIOR_HIGH)); + users.add(new User("王五2", "123", Level.SENIOR_HIGH)); + users.add(new User("王五3", "123", Level.SENIOR_HIGH)); + } +} diff --git a/src/model/Level.java b/src/model/Level.java new file mode 100644 index 0000000..577175e --- /dev/null +++ b/src/model/Level.java @@ -0,0 +1,26 @@ +package model; + +public enum Level { + ELEMENTARY("小学"), + JUNIOR_HIGH("初中"), + SENIOR_HIGH("高中"); + + private final String name; + + Level(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Level fromString(String text) { + for (Level b : Level.values()) { + if (b.name.equalsIgnoreCase(text)) { + return b; + } + } + return null; + } +} \ No newline at end of file diff --git a/src/model/User.java b/src/model/User.java new file mode 100644 index 0000000..781739f --- /dev/null +++ b/src/model/User.java @@ -0,0 +1,25 @@ +package model; + +public class User { + private final String username; + private final String password; + private final Level level; + + public User(String username, String password, Level level) { + this.username = username; + this.password = password; + this.level = level; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public Level getLevel() { + return level; + } +} \ No newline at end of file