You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}
}
}