|
|
|
|
@ -79,10 +79,10 @@ public class Application {
|
|
|
|
|
* 处理用户已登录状态下的逻辑。
|
|
|
|
|
*/
|
|
|
|
|
private void handleLoggedInState() throws IOException {
|
|
|
|
|
String currentLevelName = sessionManager.getCurrentLevelName();
|
|
|
|
|
String currentLevel = sessionManager.getCurrentLevelName();
|
|
|
|
|
System.out.printf(
|
|
|
|
|
"当前选择为%s出题。请输入生成题目数量(10-30),或输入 '切换为XX',或输入 '-1' 退出登录:%n",
|
|
|
|
|
currentLevelName);
|
|
|
|
|
currentLevel);
|
|
|
|
|
String input = scanner.nextLine().trim();
|
|
|
|
|
|
|
|
|
|
if ("-1".equals(input)) {
|
|
|
|
|
@ -90,10 +90,7 @@ public class Application {
|
|
|
|
|
} else if (isSwitchCommand(input)) {
|
|
|
|
|
handleSwitchLevel(input);
|
|
|
|
|
} else if (isNumeric(input)) {
|
|
|
|
|
int count = Integer.parseInt(input);
|
|
|
|
|
if(validateGenerateCount(count)) {
|
|
|
|
|
handleGenerateProblems(count);
|
|
|
|
|
}
|
|
|
|
|
handleGenerateProblems(input);
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("无效的选项,请重新输入");
|
|
|
|
|
}
|
|
|
|
|
@ -116,7 +113,8 @@ public class Application {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleGenerateProblems(int count) throws IOException {
|
|
|
|
|
private void handleGenerateProblems(String input) throws IOException {
|
|
|
|
|
int count = Integer.parseInt(input);
|
|
|
|
|
User currentUser = sessionManager.getCurrentUser();
|
|
|
|
|
System.out.println("正在加载历史题目,请稍候...");
|
|
|
|
|
Set<String> history = fileService.loadAllProblemHistory(currentUser);
|
|
|
|
|
@ -125,11 +123,10 @@ public class Application {
|
|
|
|
|
System.out.println("正在生成 " + count + " 道不重复的新题目...");
|
|
|
|
|
IProblemGenerator generator = sessionManager.getCurrentGenerator();
|
|
|
|
|
List<Equation> newProblems = generator.generate(count, history);
|
|
|
|
|
//命令行显示生成题目
|
|
|
|
|
// 命令行显示生成题目
|
|
|
|
|
for (int i = 0; i < newProblems.size(); i++) {
|
|
|
|
|
String problemLine = (i + 1) + ". " + newProblems.get(i).toString();
|
|
|
|
|
System.out.println(problemLine);
|
|
|
|
|
// 满足题目之间空一行的格式要求
|
|
|
|
|
System.out.println();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -143,15 +140,15 @@ public class Application {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isNumeric(String str) {
|
|
|
|
|
return str != null && str.matches("-?\\d+");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean validateGenerateCount(int count) {
|
|
|
|
|
if (count < 10 || count > 30) {
|
|
|
|
|
System.out.println("生成数量必须在10到30之间。");
|
|
|
|
|
return false;
|
|
|
|
|
if (str != null && str.matches("\\d+")){
|
|
|
|
|
int count = Integer.parseInt(str);
|
|
|
|
|
if (count < 10 || count > 30) {
|
|
|
|
|
System.out.println("生成数量必须在10到30之间。");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
|