|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.List;
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
/**
|
|
|
* 主程序:中小学数学卷子自动生成器。
|
|
|
*/
|
|
|
private static final Scanner SCANNER = new Scanner(System.in, StandardCharsets.UTF_8);
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println("=== 中小学数学卷子自动生成程序 ===");
|
|
|
while (true) {
|
|
|
Login.Account user = Login.loginLoop();
|
|
|
if (user == null) {
|
|
|
continue;
|
|
|
}
|
|
|
Login.Level currentLevel = user.level;
|
|
|
System.out.println("当前选择为 " + LanguageSwitch.levelToChinese(currentLevel) + "出题");
|
|
|
boolean loggedIn = true;
|
|
|
while (loggedIn) {
|
|
|
System.out.print("系统提示“准备生成 " + LanguageSwitch.levelToChinese(currentLevel)
|
|
|
+ "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):”\n> ");
|
|
|
String line = SCANNER.nextLine().trim();
|
|
|
if (line.equals("-1")) {
|
|
|
System.out.println("退出当前用户,返回登录界面。");
|
|
|
loggedIn = false;
|
|
|
break;
|
|
|
}
|
|
|
if (line.startsWith("切换为")) {
|
|
|
String target = line.substring("切换为".length()).trim();
|
|
|
if (target.isEmpty()) {
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
continue;
|
|
|
}
|
|
|
Login.Level newLevel = LanguageSwitch.chineseToLevel(target);
|
|
|
if (newLevel == null) {
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
} else {
|
|
|
currentLevel = newLevel;
|
|
|
System.out.println(
|
|
|
"切换成功。当前选择为 " + LanguageSwitch.levelToChinese(currentLevel) + "出题");
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
int n;
|
|
|
try {
|
|
|
n = Integer.parseInt(line);
|
|
|
} catch (NumberFormatException e) {
|
|
|
System.out.println("请输入有效的整数(10-30,或-1退出)或 '切换为 XX'。");
|
|
|
continue;
|
|
|
}
|
|
|
if (n == -1) {
|
|
|
System.out.println("退出当前用户,返回登录界面。");
|
|
|
loggedIn = false;
|
|
|
break;
|
|
|
}
|
|
|
if (n < 10 || n > 30) {
|
|
|
System.out.println("题目数量的有效输入范围是“10-30”(含10,30,或-1退出登录)。");
|
|
|
continue;
|
|
|
}
|
|
|
// 生成题目
|
|
|
List<String> existing = LoadFile.loadExistingQuestions(user.username);
|
|
|
Generator.QuestionGenerator qg = new Generator.QuestionGenerator(currentLevel, existing);
|
|
|
List<String> paper = qg.generatePaper(n);
|
|
|
if (paper.isEmpty()) {
|
|
|
System.out.println("未能生成题目(可能因去重约束导致)。");
|
|
|
} else {
|
|
|
// 保存文件
|
|
|
String savedPath = Save.savePaper(user.username, paper);
|
|
|
System.out.println("已生成 " + paper.size() + " 道题,保存为: " + savedPath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |