|
|
|
|
@ -20,8 +20,6 @@ public class Application {
|
|
|
|
|
|
|
|
|
|
// 用于解析“切换为XX”命令的正则表达式
|
|
|
|
|
private static final Pattern SWITCH_COMMAND_PATTERN = Pattern.compile("^切换为(小学|初中|高中)$");
|
|
|
|
|
private static final int MIN_GENERATE_COUNT = 10;
|
|
|
|
|
private static final int MAX_GENERATE_COUNT = 30;
|
|
|
|
|
|
|
|
|
|
public Application() {
|
|
|
|
|
this.scanner = new Scanner(System.in, "UTF-8");
|
|
|
|
|
@ -71,7 +69,7 @@ public class Application {
|
|
|
|
|
Optional<User> userOptional = authService.login(credentials[0], credentials[1]);
|
|
|
|
|
if (userOptional.isPresent()) {
|
|
|
|
|
sessionManager.startSession(userOptional.get());
|
|
|
|
|
System.out.println("登录成功!欢迎您," + userOptional.get().getUsername() + "。");
|
|
|
|
|
System.out.println("登录成功!欢迎您," + credentials[0] + "。");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("用户名或密码错误,请重试。");
|
|
|
|
|
}
|
|
|
|
|
@ -83,22 +81,21 @@ public class Application {
|
|
|
|
|
private void handleLoggedInState() throws IOException {
|
|
|
|
|
String currentLevelName = sessionManager.getCurrentLevelName();
|
|
|
|
|
System.out.printf(
|
|
|
|
|
"当前选择为%s出题。请输入生成题目数量(%d-%d),或输入 '切换为XX',或输入 '-1' 退出登录:%n",
|
|
|
|
|
currentLevelName, MIN_GENERATE_COUNT, MAX_GENERATE_COUNT);
|
|
|
|
|
"当前选择为%s出题。请输入生成题目数量(10-30),或输入 '切换为XX',或输入 '-1' 退出登录:%n",
|
|
|
|
|
currentLevelName);
|
|
|
|
|
String input = scanner.nextLine().trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("-1".equals(input)) {
|
|
|
|
|
handleLogout();
|
|
|
|
|
} else if (isSwitchCommand(input)) {
|
|
|
|
|
handleSwitchLevel(input);
|
|
|
|
|
} else if (isNumeric(input)) {
|
|
|
|
|
int count = Integer.parseInt(input);
|
|
|
|
|
validateGenerateCount(count);
|
|
|
|
|
handleGenerateProblems(count);
|
|
|
|
|
if(validateGenerateCount(count)) {
|
|
|
|
|
handleGenerateProblems(count);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("无效的选项,请重新输入");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -150,10 +147,12 @@ public class Application {
|
|
|
|
|
return str != null && str.matches("-?\\d+");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateGenerateCount(int count) {
|
|
|
|
|
if (count < MIN_GENERATE_COUNT || count > MAX_GENERATE_COUNT) {
|
|
|
|
|
private boolean validateGenerateCount(int count) {
|
|
|
|
|
if (count < 10 || count > 30) {
|
|
|
|
|
System.out.println("生成数量必须在10到30之间。");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
|