添加了使用大模型文档,更新代码

develop
LYQ 7 months ago
parent 33786ac0ee
commit eacdceb9dc

@ -24,19 +24,29 @@
## 3. 如何运行
本项目已打包为可执行的 `.jar` 文件。
本项目最终交付的可执行文件位于 `src` 目录下。请按照以下步骤运行程序:
1. 请确保您的计算机已安装 Java 运行环境 (JRE 8 或更高版本)。
1. **检查Java环境**
确保您的计算机已安装 Java 8 (JDK 1.8) 或更高版本的 JRE。您可以在命令行工具中执行 `java -version` 来进行验证。
2. 打开命令行工具 (CMD, PowerShell, Terminal)。
2. **启动程序**
打开您的命令行工具(如 Windows 的 CMD 或 PowerShellmacOS/Linux 的 Terminal然后执行以下两个步骤
3. 使用 `cd` 命令切换到 `.jar` 文件所在的目录。
**第一步:进入 `.jar` 文件所在的 `src` 目录。**
您需要使用 `cd` 命令切换到 `src` 文件夹。例如,如果您的整个项目文件夹在桌面上,命令可能如下:
```bash
# 这是一个示例路径,请根据您的实际情况修改
cd C:\Users\YourName\Desktop\MyMathQuiz_New\src
```
4. 运行以下命令启动程序:
**第二步:执行 .jar 文件。**
`src` 目录下,运行以下命令来启动数学卷子生成程序:
```bash
java -jar MyMathQuiz_New.jar
```
*(注意: `MyMathQuiz_New.jar` 是我们项目默认的打包文件名,如果您的文件名不同,请相应修改)*
```bash
java -jar MyMathQuiz_New.jar
```
成功执行后,您将在命令行看到程序的欢迎界面和登录提示。
## 4. 代码结构

@ -1,4 +1,4 @@
package com.student.mathquiz;// src/com.student.mathquiz.Main.java
package com.student.mathquiz; // src/com/student/mathquiz/Main.java
import java.util.ArrayList;
import java.util.List;
@ -6,21 +6,19 @@ import java.util.Scanner;
import java.util.Set;
/**
*.
* .
*/
public class Main {
private static Scanner scanner = new Scanner(System.in);
private static String currentUsername = null;
private static UserType currentUserType = null;
/**
* .
* @param args
* .
*
* @param args
*/
public static void main(String[] args) {
System.out.println("--- Main method started. If you see this, the JAR is running! ---");
System.out.println("--- 中小学数学卷子自动生成程序 ---");
while (true) {
login();
@ -30,6 +28,9 @@ public class Main {
}
}
/**
* .
*/
private static void login() {
currentUsername = null;
currentUserType = null;
@ -42,7 +43,7 @@ public class Main {
System.exit(0);
}
String[] credentials = input.split("\\s+");
final String[] credentials = input.split("\\s+");
if (credentials.length != 2) {
System.out.println("输入格式不正确,请重新输入。");
@ -63,6 +64,9 @@ public class Main {
}
}
/**
* .
*/
private static void handleLoggedInUser() {
while (true) {
System.out.println("\n准备生成 " + currentUserType.name() + " 数学题目,请输入生成题目数量(输入-1将退出当前用户重新登录");
@ -86,11 +90,17 @@ public class Main {
System.out.println("题目数量的有效输入范围是“10-30”或-1退出登录请重新输入。");
}
} catch (NumberFormatException e) {
System.out.println("输入无效,请输入数字或'切换为 XX'命令。");
System.out.println("错误:请输入一个有效的数字!");
}
// 修改
}
}
/**
* .
*
* @param input
*/
private static void handleSwitchType(String input) {
String typeStr = input.substring("切换为".length()).trim();
UserType newType = UserType.fromString(typeStr);
@ -102,19 +112,44 @@ public class Main {
}
}
// =================================================================
// ★★★★★★★★★★★★★ 看这里!重构的艺术! ★★★★★★★★★★★★★
// =================================================================
/**
*Object.
* ().
* .
*
* @param count
*/
public Main() {
super();
}
private static void generateAndSaveQuiz(int count) {
System.out.println("正在生成 " + count + " 道不重复的 " + currentUserType.name() + " 题目,请稍候...");
// 任务1: 派发给“造题专家”去造题
List<String> newQuestions = createNewUniqueQuestions(count);
// 任务2: 检查“专家”的工作成果
if (newQuestions.size() < count) {
System.out.println("警告:未能生成足够数量的不重复题目。");
System.out.println("本次成功生成 " + newQuestions.size() + " 道题目。");
}
// 任务3: 派发给“文件管理员”去保存
if (!newQuestions.isEmpty()) {
QuizManager.saveQuizToFile(currentUsername, newQuestions);
}
}
/**
* .
*
* @param count
* @return
*/
private static List<String> createNewUniqueQuestions(int count) {
Set<String> existingQuestions = QuizManager.loadExistingQuestions(currentUsername);
List<String> newQuestions = new ArrayList<>();
int maxTries = count * 200; // 增加尝试次数,因为题目随机性更强
int maxTries = count * 200;
int tries = 0;
while (newQuestions.size() < count && tries < maxTries) {
@ -124,14 +159,6 @@ public class Main {
}
tries++;
}
if (newQuestions.size() < count) {
System.out.println("警告:未能生成足够数量的不重复题目。可能需要更多尝试。");
System.out.println("本次成功生成 " + newQuestions.size() + " 道题目。");
}
if (!newQuestions.isEmpty()) {
QuizManager.saveQuizToFile(currentUsername, newQuestions);
}
return newQuestions;
}
}

@ -1,4 +1,4 @@
package com.student.mathquiz;// src/com.student.mathquiz.QuestionGenerator.java
package com.student.mathquiz; // src/com.student.mathquiz.QuestionGenerator.java
import java.util.ArrayList;
import java.util.List;

@ -1,4 +1,4 @@
package com.student.mathquiz;// src/com.student.mathquiz.QuizManager.java
package com.student.mathquiz; // src/com.student.mathquiz.QuizManager.java
import java.io.BufferedReader;
import java.io.BufferedWriter;

@ -1,4 +1,4 @@
package com.student.mathquiz;// src/com.student.mathquiz.UserDatabase.java
package com.student.mathquiz; // src/com.student.mathquiz.UserDatabase.java
import java.util.HashMap;
import java.util.Map;

@ -1,4 +1,4 @@
package com.student.mathquiz;// src/com.student.mathquiz.UserType.java
package com.student.mathquiz; // src/com.student.mathquiz.UserType.java
/**
* .

Loading…
Cancel
Save