diff --git a/.idea/encodings.xml b/.idea/encodings.xml index ec4453f..5dc3fb2 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index d843f34..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7371618 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +## MathSystem(出题系统) + +一个基于 Java 的命令行数学题生成器,按“小学/初中/高中”难度随机生成题目,支持去重并按账号分类保存为 `txt` 文件。 + +### 运行环境 +- JDK 17(或兼容版本) +- Windows / macOS / Linux 终端 + +### 编译与运行 +在项目根目录执行: + +```bash +javac src/Main.java +java -cp src Main +``` + +如在 Windows PowerShell 中出现中文显示为 `????`,建议使用 UTF-8 编码运行: + +```powershell +chcp 65001 +[Console]::InputEncoding = [System.Text.UTF8Encoding]::new() +[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() + +javac src/Main.java +java -Dfile.encoding=UTF-8 -cp src Main +``` + +或在 `cmd` 中: + +```cmd +chcp 65001 +javac src\Main.java +java -Dfile.encoding=UTF-8 -cp src Main +``` + +### 使用说明 +1. 启动后,按照提示输入“用户名 密码”(以空格分隔)。 +2. 登录成功后,会显示当前难度(与账号绑定)。 +3. 生成题目:输入题目数量(10-30 的整数)。 +4. 退出当前账号:输入 `-1`。 +5. 切换难度:输入 `切换为小学`、`切换为初中` 或 `切换为高中`。 + +### 输出 +- 生成的题目保存在 `papers/<用户名>/yyyy-M-d-H-m-s.txt`。 +- 同一账号历史题目用于去重,尽量避免重复。 + +### 预置账号 +- 小学:`张三1/123`、`张三2/123`、`张三3/123` +- 初中:`李四1/123`、`李四2/123`、`李四3/123` +- 高中:`王五1/123`、`王五2/123`、`王五3/123` + +### 目录结构 +``` +MathSystem/ + src/ + Main.java + papers/ # 运行后按用户生成 + README.md +``` + +### 常见问题 +- 终端中文为 `????`:按照上面的 UTF-8 设置运行;或使用 IDE 的“UTF-8 编码 + 运行”配置。 +- 无法创建输出目录:确认对项目目录有写权限,或手动创建 `papers` 目录。 + + diff --git a/papers/zhangsan1/2025-9-25-17-19-1.txt b/papers/zhangsan1/2025-9-25-17-19-1.txt new file mode 100644 index 0000000..9aa320f --- /dev/null +++ b/papers/zhangsan1/2025-9-25-17-19-1.txt @@ -0,0 +1,20 @@ +1. (85 * 85 * 48) + +2. (8 / 8 * 76) + +3. 31 + 30 + 43 + +4. (65 * 8 / 8) + +5. 69 / 69 + +6. 53 + (34 / 1 / 1) / 1 + +7. ((37 + 98 / )98) + +8. (63 / 9 + 38) + +9. 73 / (73 / 1 + 93) + +10. 65 * 67 + diff --git a/src/Main.java b/src/Main.java index 3b77df8..213a119 100644 --- a/src/Main.java +++ b/src/Main.java @@ -35,9 +35,9 @@ public class Main { public static void main(String[] args) { initAccounts(); - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); + Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8.name()); while (true) { - Account login = loginLoop(reader); + Account login = loginLoop(scanner); if (login == null) { break; } @@ -46,7 +46,7 @@ public class Main { // 登录后的工作循环 while (true) { System.out.println("准备生成" + currentLevel + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录)"); - String line = readLineTrim(reader); + String line = readLineTrim(scanner); if (line == null) return; // EOF // 支持命令:切换为XX if (line.startsWith("切换为")) { @@ -103,14 +103,15 @@ public class Main { USER_MAP.put("王五3", new Account("王五3", "123", Level.高中)); } - private static Account loginLoop(BufferedReader reader) { + private static Account loginLoop(Scanner scanner) { + System.out.println("请输入用户名和密码(用空格分隔),或输入-1退出:"); while (true) { - System.out.println("请输入用户名和密码(用空格分隔),或按Ctrl+D退出:"); - String line = readLineTrim(reader); + String line = readLineTrim(scanner); if (line == null) return null; // EOF 退出 + if ("-1".equals(line)) return null; // 主动输入-1退出 String[] parts = line.split("\\s+"); if (parts.length != 2) { - System.out.println("请按格式输入"); + System.out.println("请输入正确的用户名、密码,或输入-1退出"); continue; } String username = parts[0]; @@ -119,18 +120,15 @@ public class Main { if (acc != null && Objects.equals(acc.password, password)) { return acc; } - System.out.println("请输入正确的用户名、密码"); + System.out.println("请输入正确的用户名、密码,或输入-1退出"); } } - private static String readLineTrim(BufferedReader reader) { - try { - String s = reader.readLine(); - if (s == null) return null; - return s.trim(); - } catch (IOException e) { - return null; - } + private static String readLineTrim(Scanner scanner) { + if (!scanner.hasNextLine()) return null; + String s = scanner.nextLine(); + if (s == null) return null; + return s.trim(); } private static Level parseLevel(String s) {