|
|
|
|
@ -1,17 +1,29 @@
|
|
|
|
|
package src;
|
|
|
|
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class SysFunc {
|
|
|
|
|
// 题目数量
|
|
|
|
|
static final int LEAST_NUM = 10;
|
|
|
|
|
static final int MAX_NUM = 30;
|
|
|
|
|
// 用户列表
|
|
|
|
|
static ArrayList<Teacher> teachers;
|
|
|
|
|
// 当前用户
|
|
|
|
|
static Teacher teacher;
|
|
|
|
|
static Teacher teacher;
|
|
|
|
|
|
|
|
|
|
static HashMap<String, Integer> typeMap;
|
|
|
|
|
|
|
|
|
|
// ANSI颜色代码
|
|
|
|
|
static final String RESET = "\u001B[0m";
|
|
|
|
|
static final String RED = "\u001B[31m";
|
|
|
|
|
static final String GREEN = "\u001B[32m";
|
|
|
|
|
static final String YELLOW = "\u001B[33m";
|
|
|
|
|
static final String BLUE = "\u001B[34m";
|
|
|
|
|
static final String PURPLE = "\u001B[35m";
|
|
|
|
|
static final String CYAN = "\u001B[36m";
|
|
|
|
|
static final String BOLD = "\u001B[1m";
|
|
|
|
|
|
|
|
|
|
public static void init(){
|
|
|
|
|
// 用户预加载
|
|
|
|
|
@ -31,15 +43,18 @@ public class SysFunc {
|
|
|
|
|
typeMap.put("高中", 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登陆界面
|
|
|
|
|
public static Teacher login(Scanner scanner) {
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
// 登录界面
|
|
|
|
|
while(!flag){
|
|
|
|
|
System.out.println("-------请登录您的账户-------");
|
|
|
|
|
System.out.println(" 请输入: 用户名 密码 ");
|
|
|
|
|
System.out.println(BOLD + CYAN + "=== 数学题目生成系统 ===" + RESET);
|
|
|
|
|
System.out.println(BOLD + CYAN + "请登录您的账户" + RESET);
|
|
|
|
|
while (!flag) {
|
|
|
|
|
System.out.println(BOLD + YELLOW + "请输入: 用户名 密码" + RESET);
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
|
|
|
|
|
String cur = scanner.nextLine();
|
|
|
|
|
if (cur.indexOf(" ") == -1) {
|
|
|
|
|
System.out.println("请输入用户名和密码,中间用空格隔开");
|
|
|
|
|
System.out.println(RED + "请输入用户名和密码,中间用空格隔开");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String cur_name = cur.substring(0, cur.indexOf(" "));
|
|
|
|
|
@ -50,46 +65,50 @@ public class SysFunc {
|
|
|
|
|
if (t.name.equals(cur_name) && t.password.equals(cur_password)) {
|
|
|
|
|
teacher = t;
|
|
|
|
|
flag = true;
|
|
|
|
|
System.out.println("当前选择为" + teacher.getType() + "出题");
|
|
|
|
|
System.out.println(GREEN + "当前选择为" + teacher.getType() + "出题");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag) {
|
|
|
|
|
System.out.println("请输入正确的用户名、密码");
|
|
|
|
|
System.out.println(RED + "请输入正确的用户名、密码");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return teacher;
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 切换类型界面
|
|
|
|
|
public static void ShiftType(Scanner scanner) {
|
|
|
|
|
int type = SysFunc.typeMap.get(SysFunc.teacher.getType());
|
|
|
|
|
System.out.println("-------是否切换出题类型(y/n)-------");
|
|
|
|
|
String choice = scanner.nextLine();
|
|
|
|
|
if (choice.equals("y")) {
|
|
|
|
|
System.out.println("请输入类型(切换**)支持小学,初中,高中难度:");
|
|
|
|
|
while (true) {
|
|
|
|
|
String choice_type = scanner.nextLine();
|
|
|
|
|
if (choice_type.substring(0, 2).equals("切换") && typeMap.containsKey(choice_type.substring(2))) {
|
|
|
|
|
type = typeMap.get(choice_type.substring(2));
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
teacher = new PrimaryTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
} else if (type == 2) {
|
|
|
|
|
teacher = new JuniorTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
} else {
|
|
|
|
|
teacher = new SeniorTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
break;
|
|
|
|
|
System.out.println(BOLD + PURPLE + "=== 是否切换出题类型(y/n) ===" + RESET);
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
|
|
|
|
|
String choice = scanner.nextLine();
|
|
|
|
|
if (choice.equals("y")) {
|
|
|
|
|
System.out.println(BOLD + YELLOW + "请输入指令: 切换** (支持小学,初中,高中难度): " + RESET);
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
String choice_type = scanner.nextLine();
|
|
|
|
|
if (choice_type.substring(0, 2).equals("切换") && typeMap.containsKey(choice_type.substring(2))) {
|
|
|
|
|
type = typeMap.get(choice_type.substring(2));
|
|
|
|
|
if (type == 1) {
|
|
|
|
|
teacher = new PrimaryTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
} else if (type == 2) {
|
|
|
|
|
teacher = new JuniorTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
teacher = new SeniorTea(teacher.name, teacher.password, teacher.path);
|
|
|
|
|
}
|
|
|
|
|
System.out.println(GREEN + "准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(RED + RESET + "请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
}
|
|
|
|
|
} else if (choice.equals("n")) {
|
|
|
|
|
System.out.println("请继续输入题目数量:");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("无效输入,已为您设置默认类型");
|
|
|
|
|
}
|
|
|
|
|
} else if (choice.equals("n")) {
|
|
|
|
|
System.out.println(GREEN + "请继续输入题目数量:");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(RED + RESET + "无效输入,已为您设置默认类型:" + teacher.getType());
|
|
|
|
|
System.out.println(GREEN + "请输入题目数量:");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,30 +120,33 @@ public class SysFunc {
|
|
|
|
|
int num = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
String input = scanner.nextLine();
|
|
|
|
|
num = Integer.parseInt(input);
|
|
|
|
|
break;
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("请输入有效的数字(10-30之间的整数,或-1退出登录):");
|
|
|
|
|
System.out.println(RED + RESET + "请输入有效的数字(10-30之间的整数,或-1退出登录):");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (true) {
|
|
|
|
|
if (num == -1) {
|
|
|
|
|
// 返回登录界面
|
|
|
|
|
System.out.println("已退出登录");
|
|
|
|
|
System.out.println(BOLD + YELLOW + "已退出登录" + RESET);
|
|
|
|
|
logout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (num >= LEAST_NUM && num <= MAX_NUM) {
|
|
|
|
|
String filepath = teacher.GenerateEX(num);
|
|
|
|
|
System.out.println("题目生成成功,已保存至" + filepath);
|
|
|
|
|
System.out.println(BOLD + GREEN + "正在生成题目..." + RESET);
|
|
|
|
|
String filepath = teacher.generateEX(num);
|
|
|
|
|
System.out.println(GREEN + RESET + "题目生成成功,已保存至" + filepath);
|
|
|
|
|
System.out.println(BOLD + CYAN + "=== 操作完成 ===" + RESET);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("题目数量应在10-30之间,请重新输入");
|
|
|
|
|
System.out.println(RED + RESET + "题目数量应在10-30之间,请重新输入");
|
|
|
|
|
try {
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
num = Integer.parseInt(scanner.nextLine());
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println("请输入有效的数字:");
|
|
|
|
|
System.out.println(RED + RESET + "请输入有效的数字:");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|