修复乱码

pull/2/head
杨默涵 4 days ago
parent f201473d99
commit 9a0d87ba40

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="GBK" addBOMForNewFiles="with BOM">
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8" addBOMForNewFiles="with BOM">
<file url="file://$PROJECT_DIR$/src/Main.java" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -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` 目录。

@ -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

@ -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) {

Loading…
Cancel
Save