diff --git a/doc/双击启动.bat b/doc/双击启动.bat new file mode 100644 index 0000000..05146d9 --- /dev/null +++ b/doc/双击启动.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 mathgenerator.jar + +:: 4. 清理环境变量并暂停,以便查看程序输出 +set JAVA_TOOL_OPTIONS= +pause \ No newline at end of file diff --git a/doc/程序运行说明.md b/doc/程序运行说明.md new file mode 100644 index 0000000..f2d3a76 --- /dev/null +++ b/doc/程序运行说明.md @@ -0,0 +1,12 @@ +# 程序运行说明 + +1. 环境配置:java21及以上,不推荐使用windows,要设置更改字符,否则中文字符会乱码,建议使用ubuntu,macos等系统 +2. 在控制台输入 + + ```bash + java -jar mathgenerator.jar + ``` + + 可以开始使用程序 +3. 程序提供在windows运行的bat脚本,需要可以双击运行 +4. 注册功能的说明:注册功能是自己添加,由于项目要求登录时将用户名和密码同行隔空格输入,因此注册时的特殊情况,如密码含空格,会无法登录,但是登录不是课程考核之一,希望不要引起不必要的误会,特此说明 \ 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 4cb4e2e..c7ee06b 100644 --- a/src/main/java/com/mathgenerator/ui/ConsoleUI.java +++ b/src/main/java/com/mathgenerator/ui/ConsoleUI.java @@ -81,27 +81,37 @@ public class ConsoleUI { */ private void handleRegistration() { printHeader("新用户注册"); - System.out.print("请输入新用户名: "); - String username = scanner.nextLine().trim(); + System.out.print("请输入用户名和密码(用空格分隔): "); + String input = scanner.nextLine().trim(); + if (input.isEmpty()) { + System.out.println("输入不能为空。"); + return; + } + // 按空格分割,只分割成两部分:用户名 和 密码(后面部分允许包含空格) + String[] parts = input.split("\\s+", 2); // 最多分割成2部分 + if (parts.length != 2) { + System.out.println("格式错误:请输入 '用户名 密码',用空格分隔。"); + return; + } + String username = parts[0].trim(); + String password = parts[1].trim(); // 允许密码包含空格 + if (username.isEmpty() || password.isEmpty()) { + System.out.println("用户名或密码不能为空。"); + return; + } if (userService.findUserByUsername(username).isPresent()) { System.out.println("注册失败:该用户名已被占用。"); return; } - - System.out.print("请输入密码: "); - String password = scanner.nextLine().trim(); - Level level = selectLevelForRegistration(); if (level == null) { System.out.println("操作已取消。"); return; } - if (userService.register(username, password, level)) { System.out.println("注册成功!现在您可以使用新账户登录了。"); } else { - // 理论上,这里的失败分支不会被触发,因为我们已经提前检查了用户名 System.out.println("注册失败,发生未知错误。"); } }