|
|
|
@ -0,0 +1,141 @@
|
|
|
|
|
// problem.java
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 问题管理类,处理用户交互和题目生成流程。
|
|
|
|
|
*/
|
|
|
|
|
public class ProblemManager {
|
|
|
|
|
private String currentLevel;
|
|
|
|
|
private String currentUserName;
|
|
|
|
|
|
|
|
|
|
public void display() {
|
|
|
|
|
try {
|
|
|
|
|
new ProcessBuilder("clear").inheritIO().start().waitFor();
|
|
|
|
|
} catch (IOException | InterruptedException exception) {
|
|
|
|
|
// 清屏失败,继续执行
|
|
|
|
|
}
|
|
|
|
|
System.out.println("=== 中小学数学卷子自动生成程序 ===");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void start(User user) {
|
|
|
|
|
currentLevel = user.getLevel();
|
|
|
|
|
currentUserName = user.getUsername();
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
display();
|
|
|
|
|
System.out.println("欢迎你 " + user.getUsername() + " " + currentLevel);
|
|
|
|
|
System.out.println("输入1开始出题");
|
|
|
|
|
System.out.println("输入2切换出题年级");
|
|
|
|
|
System.out.println("输入-1退出登录,返回开始界面");
|
|
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
int choice = 0;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
String input = scanner.next();
|
|
|
|
|
try {
|
|
|
|
|
choice = Integer.parseInt(input);
|
|
|
|
|
} catch (NumberFormatException exception) {
|
|
|
|
|
choice = 0;
|
|
|
|
|
}
|
|
|
|
|
if (choice == 1 || choice == 2 || choice == -1) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("请输入正确的操作");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (choice == 1) {
|
|
|
|
|
if (generateProblems() == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (choice == 2) {
|
|
|
|
|
if (switchLevel() == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (choice == -1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int generateProblems() {
|
|
|
|
|
System.out.println("正在为" + currentLevel + "出题");
|
|
|
|
|
System.out.println("请在10-30的范围内输入出题数目,输入-1返回操作界面");
|
|
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
int problemCount = 0;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
String input = scanner.next();
|
|
|
|
|
try {
|
|
|
|
|
problemCount = Integer.parseInt(input);
|
|
|
|
|
} catch (NumberFormatException exception) {
|
|
|
|
|
problemCount = 0;
|
|
|
|
|
}
|
|
|
|
|
if (problemCount == -1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (problemCount >= 10 && problemCount <= 30) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("请输入10-30范围的出题数");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (problemCount == -1) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentLevel.equals("小学")) {
|
|
|
|
|
PrimarySchoolProblemGenerator primaryGenerator = new PrimarySchoolProblemGenerator();
|
|
|
|
|
primaryGenerator.start(problemCount, currentUserName);
|
|
|
|
|
} else if (currentLevel.equals("初中")) {
|
|
|
|
|
MiddleSchoolProblemGenerator middleGenerator = new MiddleSchoolProblemGenerator();
|
|
|
|
|
middleGenerator.start(problemCount, currentUserName);
|
|
|
|
|
} else if (currentLevel.equals("高中")) {
|
|
|
|
|
HighSchoolProblemGenerator highGenerator = new HighSchoolProblemGenerator();
|
|
|
|
|
highGenerator.start(problemCount, currentUserName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("已出题完成,输入-1返回操作界面");
|
|
|
|
|
while (!scanner.next().equals("-1")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int switchLevel() {
|
|
|
|
|
System.out.println("请输入想要切换的出题年级,输入-1返回操作界面");
|
|
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
String newLevel;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
newLevel = scanner.next();
|
|
|
|
|
if (newLevel.equals("-1")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (newLevel.equals("初中") || newLevel.equals("小学") || newLevel.equals("高中")) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newLevel.equals("-1")) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentLevel = newLevel;
|
|
|
|
|
System.out.println("已成功修改出题年级为" + currentLevel + ",输入-1返回操作界面");
|
|
|
|
|
|
|
|
|
|
while (!scanner.next().equals("-1")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|