diff --git a/out/artifacts/TestPaperGenerationSystem_jar/TestPaperGenerationSystem.jar b/TestPaperGenerationSystem.jar similarity index 61% rename from out/artifacts/TestPaperGenerationSystem_jar/TestPaperGenerationSystem.jar rename to TestPaperGenerationSystem.jar index 6df1299..7c4fd3b 100644 Binary files a/out/artifacts/TestPaperGenerationSystem_jar/TestPaperGenerationSystem.jar and b/TestPaperGenerationSystem.jar differ diff --git a/account/account.txt b/account/account.txt index 0c40ab4..2ed9c9b 100644 --- a/account/account.txt +++ b/account/account.txt @@ -6,4 +6,5 @@ 李四3,123,初中 王五1,123,高中 王五2,123,高中 -王五3,123,高中 \ No newline at end of file +王五3,123,高中 +abc1,123,高中 \ No newline at end of file diff --git a/data/abc1/2025-09-25-23-32-56.txt b/data/abc1/2025-09-25-23-32-56.txt new file mode 100644 index 0000000..b1ebb8f --- /dev/null +++ b/data/abc1/2025-09-25-23-32-56.txt @@ -0,0 +1,19 @@ +1. (45^2) * (5 - sin(45) - 7 * 94 = ? + +2. cos(60) + 74 = ? + +3. 47 - cos(45) - 63) = ? + +4. 25 / 5 * cos(60) + 88) * (59^2) = ? + +5. tan(30) + 8 = ? + +6. 59 * cos(45) = ? + +7. 91 * tan(0) + 100 / sqrt(9) = ? + +8. 55 / tan(60) / 70 / sqrt(64) = ? + +9. tan(0) + 69 = ? + +10. sin(60) / sqrt(25) = ? diff --git a/data/张三1/2025-09-26-12-07-17.txt b/data/张三1/2025-09-26-12-07-17.txt new file mode 100644 index 0000000..31ce557 --- /dev/null +++ b/data/张三1/2025-09-26-12-07-17.txt @@ -0,0 +1,19 @@ +1. 7 - 7 - 0 * 1 = ? + +2. 19 + 16 = ? + +3. 20 + 37 = ? + +4. 8 / 2 = ? + +5. 65 + 76 * 7 - 363 - 466 = ? + +6. 72 * (5 - 125) = ? + +7. 83 * 2 = ? + +8. 6 * 2 = ? + +9. 56 - 33 = ? + +10. 43 / 1 - 41 / 1 = ? diff --git a/data/张三1/2025-09-26-12-07-26.txt b/data/张三1/2025-09-26-12-07-26.txt new file mode 100644 index 0000000..cf42724 --- /dev/null +++ b/data/张三1/2025-09-26-12-07-26.txt @@ -0,0 +1,23 @@ +1. 19 * sin(45) + sqrt(25) = ? + +2. sin(0) / (10^2) + 91) - 24 = ? + +3. (13^2) + (97 - tan(45) = ? + +4. sin(45) - sqrt(25) = ? + +5. 119 / cos(30) + 12 + (30^2) = ? + +6. (12 - (98^2) / sin(90) / 1 * 36 = ? + +7. 67 + 53 - 60 / sin(90) * 64 = ? + +8. sqrt(81) - 60 + sin(45) + 98 = ? + +9. tan(45) - 19) / sqrt(16) = ? + +10. 26 + 7 * tan(45) = ? + +11. (59 + (97^2) - tan(0) = ? + +12. 55 * (49^2) + sin(45) + 35 = ? diff --git a/out/production/TestPaperGenerationSystem/Application.class b/out/production/TestPaperGenerationSystem/Application.class index 0d4a9d1..e27b1c4 100644 Binary files a/out/production/TestPaperGenerationSystem/Application.class and b/out/production/TestPaperGenerationSystem/Application.class differ diff --git a/out/production/TestPaperGenerationSystem/AuthService.class b/out/production/TestPaperGenerationSystem/AuthService.class index bfa23c7..95d509c 100644 Binary files a/out/production/TestPaperGenerationSystem/AuthService.class and b/out/production/TestPaperGenerationSystem/AuthService.class differ diff --git a/out/production/TestPaperGenerationSystem/UserRepository.class b/out/production/TestPaperGenerationSystem/UserRepository.class index 621f0bb..84c6af7 100644 Binary files a/out/production/TestPaperGenerationSystem/UserRepository.class and b/out/production/TestPaperGenerationSystem/UserRepository.class differ diff --git a/src/Application.java b/src/Application.java index 16790ef..23b9314 100644 --- a/src/Application.java +++ b/src/Application.java @@ -29,7 +29,7 @@ public class Application { * 通过依赖注入的方式,在这里创建并组装各个服务模块的实例,确保各模块职责单一。 */ public Application() { - this.scanner = new Scanner(System.in, "UTF-8"); + this.scanner = new Scanner(System.in); // 创建数据访问层的实例 IUserRepository userRepository = new UserRepository(); @@ -44,19 +44,24 @@ public class Application { * 启动并运行应用程序的主循环。 * 该方法会持续监听用户输入,并根据用户当前的登录状态(已登录或未登录), * 分别调用不同的处理逻辑。 - * @throws IOException 如果在处理输入输出时发生错误 */ - public void run() throws IOException { + public void run() { System.out.println("欢迎使用中小学数学卷子自动生成程序!"); while (true) { - if (!sessionManager.isUserLoggedIn()) { - handleLoggedOutState(); - } else { - handleLoggedInState(); + try { + if (!sessionManager.isUserLoggedIn()) { + handleLoggedOutState(); + } else { + handleLoggedInState(); + } + } catch (Exception e) { + System.out.println("error"); + break; } } } + /** * 处理用户未登录状态下的逻辑。 */ @@ -204,9 +209,8 @@ public class Application { * 应用程序的入口点 (main方法)。 * 负责创建 Application 实例并启动主循环,从而开始整个程序。 * @param args 命令行参数(本项目中未使用) - * @throws IOException 如果在程序运行期间发生IO错误 */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) { Application app = new Application(); app.run(); } diff --git a/src/AuthService.java b/src/AuthService.java index e9038df..52ce22d 100644 --- a/src/AuthService.java +++ b/src/AuthService.java @@ -21,7 +21,6 @@ public class AuthService implements IAuthService { */ public Optional login(String username, String password) { Optional userOptional = userRepository.findByUsername(username); - // 检查用户是否存在,以及密码是否匹配 if (userOptional.isPresent() && userOptional.get().getPassword().equals(password)) { return userOptional; diff --git a/src/UserRepository.java b/src/UserRepository.java index 0812340..09b084b 100644 --- a/src/UserRepository.java +++ b/src/UserRepository.java @@ -1,31 +1,57 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; /** * 用户仓库的内存实现。 - * 在程序启动时,预加载所有预定义的用户账户。 + * 在程序启动时,从文件中加载所有用户账户。 */ public class UserRepository implements IUserRepository { private final Map userDatabase = new ConcurrentHashMap<>(); public UserRepository() { - // 初始化预定义的9个用户账户 - // 小学老师 - 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", "初中")); - userDatabase.put("李四2", new User("李四2", "123", "初中")); - userDatabase.put("李四3", new User("李四3", "123", "初中")); - // 高中老师 - userDatabase.put("王五1", new User("王五1", "123", "高中")); - userDatabase.put("王五2", new User("王五2", "123", "高中")); - userDatabase.put("王五3", new User("王五3", "123", "高中")); + // 从文件中加载用户数据 + loadUsersFromFile(); } + /** + * 从指定的文本文件中加载用户信息。 + * 文件的每一行应遵循 "username,password,level" 格式。 + */ + private void loadUsersFromFile() { + // 使用 try-with-resources 语句确保 BufferedReader 被正确关闭 + try (BufferedReader reader = new BufferedReader(new FileReader("./account/account.txt"))) { + String line; + // 逐行读取文件 + while ((line = reader.readLine()) != null) { + // 使用逗号分割每行的数据 + String[] parts = line.split(","); + // 确保每行都有三部分:用户名、密码和用户级别 + if (parts.length == 3) { + String username = parts[0].trim(); + String password = parts[1].trim(); + String level = parts[2].trim(); + userDatabase.put(username, new User(username, password, level)); + } + } + } catch (IOException e) { + // 如果文件未找到或发生其他IO错误,打印错误信息 + System.err.println("从文件加载用户数据时出错: " + "./account/account.txt"); + } + } + + + /** + * 根据用户名查找用户。 + * + * @param username 要查找的用户的用户名。 + * @return 如果找到用户,则返回一个包含该用户的Optional; + * 如果未找到,则返回一个空的Optional + */ @Override public Optional findByUsername(String username) { return Optional.ofNullable(userDatabase.get(username)); diff --git a/双击启动.bat b/双击启动.bat new file mode 100644 index 0000000..af5264d --- /dev/null +++ b/双击启动.bat @@ -0,0 +1,14 @@ +@echo off +:: 1. 将控制台环境设置为 UTF-8,确保中文输入输出正确 +chcp 65001 > nul + +:: 2. 告诉 Java 虚拟机(JVM) 使用 UTF-8 编码 +set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 + +:: 3. 运行你的 JAR 包 +echo loading... +java -jar TestPaperGenerationSystem.jar + +:: 4. 清理环境变量并暂停,以便查看程序输出 +set JAVA_TOOL_OPTIONS= +pause \ No newline at end of file