|
|
|
|
@ -2,10 +2,6 @@ package Program;
|
|
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 主程序
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
private final Scanner scanner;
|
|
|
|
|
private final Users users;
|
|
|
|
|
@ -13,6 +9,12 @@ public class Main {
|
|
|
|
|
private String currentUser;
|
|
|
|
|
private Type currentType;
|
|
|
|
|
|
|
|
|
|
public Main() {
|
|
|
|
|
this.scanner = new Scanner(System.in);
|
|
|
|
|
this.users = new Users();
|
|
|
|
|
this.questionManager = new QuestionManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getGrade(Type type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case primary:
|
|
|
|
|
@ -26,25 +28,16 @@ public class Main {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Main() {
|
|
|
|
|
this.scanner = new Scanner(System.in);
|
|
|
|
|
this.users = new Users();
|
|
|
|
|
this.questionManager = new QuestionManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清屏函数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**清屏函数*/
|
|
|
|
|
private void clearScreen() {
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
String os = System.getProperty("os.name").toLowerCase();
|
|
|
|
|
if(os.contains("win")){
|
|
|
|
|
new ProcessBuilder("cmd","/c","cls").inheritIO().start().waitFor();
|
|
|
|
|
}else{
|
|
|
|
|
if (os.contains("win")) {
|
|
|
|
|
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
|
|
|
|
|
} else {
|
|
|
|
|
new ProcessBuilder("clear").inheritIO().start().waitFor();
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.out.print("\033[H\033[2J");
|
|
|
|
|
System.out.flush();
|
|
|
|
|
}
|
|
|
|
|
@ -53,7 +46,7 @@ public class Main {
|
|
|
|
|
@SuppressWarnings("InfiniteLoopStatement")
|
|
|
|
|
public void run() {
|
|
|
|
|
while (true) {
|
|
|
|
|
if(Login()) {
|
|
|
|
|
if (Login()) {
|
|
|
|
|
Exchange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -63,45 +56,44 @@ public class Main {
|
|
|
|
|
* 用户登录
|
|
|
|
|
* @return 登录是否成功
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private boolean Login() {
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.print("请输入用户名和密码[空格隔开]或输入‘-1’退出程序: ");
|
|
|
|
|
String input = scanner.nextLine().trim();
|
|
|
|
|
|
|
|
|
|
if("-1".equals(input)) {
|
|
|
|
|
if ("-1".equals(input)) {
|
|
|
|
|
System.out.println("程序已退出");
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] parts = input.split("\\s+");
|
|
|
|
|
if(parts.length != 2) {
|
|
|
|
|
if (parts.length != 2) {
|
|
|
|
|
System.out.println("请输入正确的用户名或密码");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String username = parts[0];
|
|
|
|
|
String password = parts[1];
|
|
|
|
|
|
|
|
|
|
Type type = users.verification(username,password);
|
|
|
|
|
if(type != null) {
|
|
|
|
|
Type type = users.verification(username, password);
|
|
|
|
|
if (type != null) {
|
|
|
|
|
currentUser = username;
|
|
|
|
|
currentType = type;
|
|
|
|
|
System.out.println("欢迎您," +currentUser+"!");
|
|
|
|
|
System.out.println("欢迎您," + currentUser + "!");
|
|
|
|
|
System.out.println("当前选择为" + getGrade(type) + "出题");
|
|
|
|
|
return true;
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("请输入正确的用户名或密码");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Exchange() {
|
|
|
|
|
while(true){
|
|
|
|
|
System.out.print("准备生成"+getGrade(currentType)
|
|
|
|
|
+"数学题目,请输入生成题目数量[10-30]或输入‘切换为’切换难度或输入‘-1’退出当前用户:");
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.print("准备生成" + getGrade(currentType)
|
|
|
|
|
+ "数学题目,请输入生成题目数量[10-30]或输入‘切换为’切换难度或输入‘-1’退出当前用户:");
|
|
|
|
|
String input = scanner.nextLine().trim();
|
|
|
|
|
|
|
|
|
|
if(input.startsWith("切换为")) {
|
|
|
|
|
if (input.startsWith("切换为")) {
|
|
|
|
|
Change(input);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
@ -109,7 +101,7 @@ public class Main {
|
|
|
|
|
try {
|
|
|
|
|
int number = Integer.parseInt(input);
|
|
|
|
|
|
|
|
|
|
if(number==-1){
|
|
|
|
|
if (number == -1) {
|
|
|
|
|
currentType = null;
|
|
|
|
|
currentUser = null;
|
|
|
|
|
clearScreen();
|
|
|
|
|
@ -117,12 +109,12 @@ public class Main {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(number<10||number>30){
|
|
|
|
|
if (number < 10 || number > 30) {
|
|
|
|
|
System.out.println("题目数量必须在10-30之间");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
makeAndSaveQuestions(number);
|
|
|
|
|
}catch(NumberFormatException e){
|
|
|
|
|
makeAndSaveQuestions(number);
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("请输入有效数字");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -132,11 +124,10 @@ public class Main {
|
|
|
|
|
* 切换命令
|
|
|
|
|
* @param input 切换命令
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private void Change(String input) {
|
|
|
|
|
String result=input.substring(3).trim();
|
|
|
|
|
String result = input.substring(3).trim();
|
|
|
|
|
|
|
|
|
|
Type newType=null;
|
|
|
|
|
Type newType = null;
|
|
|
|
|
switch (result) {
|
|
|
|
|
case "小学":
|
|
|
|
|
newType = Type.primary;
|
|
|
|
|
@ -147,16 +138,15 @@ public class Main {
|
|
|
|
|
case "高中":
|
|
|
|
|
newType = Type.high;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(newType==null) {
|
|
|
|
|
if (newType == null) {
|
|
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentType=newType;
|
|
|
|
|
System.out.println("成功切换为‘"+getGrade(newType)
|
|
|
|
|
currentType = newType;
|
|
|
|
|
System.out.println("成功切换为‘" + getGrade(newType)
|
|
|
|
|
+ "’!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -164,21 +154,20 @@ public class Main {
|
|
|
|
|
* 生成并保存题目(附带查重功能-在makeQuestions方法中实现)
|
|
|
|
|
* @param number 题目数量
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private void makeAndSaveQuestions(int number) {
|
|
|
|
|
QuestionMaker maker = createMaker(currentType);
|
|
|
|
|
java.util.Set<String> exQuestions=
|
|
|
|
|
java.util.Set<String> exQuestions =
|
|
|
|
|
questionManager.loadQuestions(currentUser);
|
|
|
|
|
|
|
|
|
|
java.util.List<String> questions=
|
|
|
|
|
maker.makeQuestions(number,exQuestions);
|
|
|
|
|
java.util.List<String> questions =
|
|
|
|
|
maker.makeQuestions(number, exQuestions);
|
|
|
|
|
|
|
|
|
|
if(questions.size()<number){
|
|
|
|
|
System.out.println("警告:由于查重限制,实际生成题目数量为:" + questions.size()+"道");
|
|
|
|
|
if (questions.size() < number) {
|
|
|
|
|
System.out.println("警告:由于查重限制,实际生成题目数量为:" + questions.size() + "道");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
questionManager.saveQuestions(currentUser,questions);
|
|
|
|
|
System.out.println(questions.size()+"道题目生成完成");
|
|
|
|
|
questionManager.saveQuestions(currentUser, questions);
|
|
|
|
|
System.out.println(questions.size() + "道题目生成完成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -186,7 +175,6 @@ public class Main {
|
|
|
|
|
* @param type 用户类型
|
|
|
|
|
* @return 题目生成
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private QuestionMaker createMaker(Type type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case primary:
|
|
|
|
|
@ -196,7 +184,7 @@ public class Main {
|
|
|
|
|
case high:
|
|
|
|
|
return new HighMaker();
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("未知的输入"+type);
|
|
|
|
|
throw new IllegalArgumentException("未知的输入" + type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -204,4 +192,4 @@ public class Main {
|
|
|
|
|
Main main = new Main();
|
|
|
|
|
main.run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|