|
|
|
@ -1,14 +1,12 @@
|
|
|
|
|
package src;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
public class App {
|
|
|
|
|
|
|
|
|
|
private static final Scanner scanner = new Scanner(System.in);
|
|
|
|
|
private static final Map<String, User> users = User.getPresetUsers();
|
|
|
|
|
private static final FileManager fileManager = new FileManager();
|
|
|
|
|
private static final FileManager FILE_MANAGER = new FileManager();
|
|
|
|
|
private static QuestionGenerator currentGenerator;
|
|
|
|
|
private static String currentUsername;
|
|
|
|
|
|
|
|
|
@ -38,21 +36,19 @@ public class App {
|
|
|
|
|
System.out.println("当前选择为 " + userType + " 出题");
|
|
|
|
|
|
|
|
|
|
// 加载已存在的题目用于查重
|
|
|
|
|
Set<String> existingQuestions = fileManager.loadExistingQuestions(currentUsername);
|
|
|
|
|
Set<String> existingQuestions = FILE_MANAGER.loadExistingQuestions(currentUsername);
|
|
|
|
|
for (String question : existingQuestions) {
|
|
|
|
|
currentGenerator.addToGenerated(question);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 主循环
|
|
|
|
|
boolean stayLoggedIn = true;
|
|
|
|
|
while (stayLoggedIn) {
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.println("\n准备生成 " + currentGenerator.getCurrentType()
|
|
|
|
|
+ " 数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
|
|
|
|
|
String input = scanner.nextLine().trim();
|
|
|
|
|
|
|
|
|
|
if (input.equals("-1")) {
|
|
|
|
|
stayLoggedIn = false;
|
|
|
|
|
System.out.println("退出当前用户...");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -81,7 +77,7 @@ public class App {
|
|
|
|
|
private static User login() {
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.println("\n请输入用户名和密码(用空格隔开):");
|
|
|
|
|
System.out.println("如果需要注册新用户,请输入'register'");
|
|
|
|
|
System.out.println("如果需要注册新用户,请输入'注册'");
|
|
|
|
|
System.out.println("如果需要退出程序,请输入'-1'");
|
|
|
|
|
String input = scanner.nextLine();
|
|
|
|
|
String[] credentials = input.split("\\s+");
|
|
|
|
@ -92,7 +88,7 @@ public class App {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理注册请求
|
|
|
|
|
if (credentials[0].equalsIgnoreCase("register")) {
|
|
|
|
|
if (credentials[0].equalsIgnoreCase("注册")) {
|
|
|
|
|
handleRegistration();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -226,7 +222,7 @@ public class App {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重新加载已存在的题目用于查重
|
|
|
|
|
Set<String> existingQuestions = fileManager.loadExistingQuestions(currentUsername);
|
|
|
|
|
Set<String> existingQuestions = FILE_MANAGER.loadExistingQuestions(currentUsername);
|
|
|
|
|
for (String question : existingQuestions) {
|
|
|
|
|
currentGenerator.addToGenerated(question);
|
|
|
|
|
}
|
|
|
|
@ -246,7 +242,7 @@ public class App {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
fileManager.saveQuestions(currentUsername, questions);
|
|
|
|
|
FILE_MANAGER.saveQuestions(currentUsername, questions);
|
|
|
|
|
System.out.println("题目生成完成!");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.println("保存文件时出错: " + e.getMessage());
|
|
|
|
|