|
|
|
|
@ -1,17 +1,38 @@
|
|
|
|
|
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";
|
|
|
|
|
// 清屏代码
|
|
|
|
|
static final String CLEAR_SCREEN = "\033[H\033[2J";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清屏方法
|
|
|
|
|
public static void clearScreen() {
|
|
|
|
|
System.out.print(CLEAR_SCREEN);
|
|
|
|
|
System.out.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void init(){
|
|
|
|
|
// 用户预加载
|
|
|
|
|
@ -31,92 +52,114 @@ public class SysFunc {
|
|
|
|
|
typeMap.put("高中", 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登陆界面
|
|
|
|
|
public static Teacher login(Scanner scanner) {
|
|
|
|
|
clearScreen();
|
|
|
|
|
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("请输入用户名和密码,中间用空格隔开");
|
|
|
|
|
if (cur.indexOf(" ") == -1) {
|
|
|
|
|
System.out.println(RED + "请输入用户名和密码,中间用空格隔开");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String cur_name = cur.substring(0, cur.indexOf(" "));
|
|
|
|
|
String cur_password = cur.substring(cur.indexOf(" ") + 1);
|
|
|
|
|
|
|
|
|
|
// 匹配已有帐户
|
|
|
|
|
for(Teacher t : teachers){
|
|
|
|
|
if(t.name.equals(cur_name) && t.password.equals(cur_password)){
|
|
|
|
|
for (Teacher t : teachers) {
|
|
|
|
|
if (t.name.equals(cur_name) && t.password.equals(cur_password)) {
|
|
|
|
|
teacher = t;
|
|
|
|
|
flag = true;
|
|
|
|
|
System.out.println("当前选择为" + teacher.getType() + "出题");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!flag){
|
|
|
|
|
System.out.println("请输入正确的用户名、密码");
|
|
|
|
|
}
|
|
|
|
|
if (!flag) {
|
|
|
|
|
System.out.println(RED + "请输入正确的用户名、密码");
|
|
|
|
|
}
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 切换类型界面
|
|
|
|
|
public static void ShiftType(Scanner scanner) {
|
|
|
|
|
System.out.println(GREEN + "当前选择为" + teacher.getType() + "出题");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
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.length() >= 5
|
|
|
|
|
&& choice_type.substring(0, 3).equals("切换为")
|
|
|
|
|
&& typeMap.containsKey(choice_type.substring(3))) {
|
|
|
|
|
type = typeMap.get(choice_type.substring(3));
|
|
|
|
|
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(GREEN + "准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(RED + RESET + "请输入小学、初中和高中三个选项中的一个 (切换为**)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(choice.equals("n")){
|
|
|
|
|
System.out.println("请继续输入题目数量:");
|
|
|
|
|
}
|
|
|
|
|
} else if (choice.equals("n")) {
|
|
|
|
|
System.out.println(GREEN + "准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(RED + RESET + "无效输入,已为您设置默认类型:" + teacher.getType());
|
|
|
|
|
System.out.println(GREEN + "准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 出题界面
|
|
|
|
|
public static void Operate(Scanner scanner){
|
|
|
|
|
boolean logout = false;
|
|
|
|
|
while(!logout){
|
|
|
|
|
while (!logout) {
|
|
|
|
|
SysFunc.ShiftType(scanner);
|
|
|
|
|
int num = scanner.nextInt();
|
|
|
|
|
scanner.nextLine();
|
|
|
|
|
while(true){
|
|
|
|
|
if(num == -1) {
|
|
|
|
|
// 返回登录界面
|
|
|
|
|
System.out.println("已退出登录");
|
|
|
|
|
logout = true;
|
|
|
|
|
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(RED + RESET + "请输入有效的数字(10-30之间的整数,或-1退出登录):");
|
|
|
|
|
}
|
|
|
|
|
if(num >= LEAST_NUM && num <= MAX_NUM) {
|
|
|
|
|
String filepath = teacher.GenerateEX(num);
|
|
|
|
|
System.out.println("题目生成成功,已保存至" + filepath);
|
|
|
|
|
}
|
|
|
|
|
while (true) {
|
|
|
|
|
if (num == -1) {
|
|
|
|
|
System.out.println(BOLD + YELLOW + "已退出登录" + RESET);
|
|
|
|
|
logout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
System.out.println("题目数量应在10-30之间,请重新输入");
|
|
|
|
|
num = scanner.nextInt();
|
|
|
|
|
if (num >= LEAST_NUM && num <= MAX_NUM) {
|
|
|
|
|
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(RED + RESET + "题目数量应在10-30之间,请重新输入");
|
|
|
|
|
try {
|
|
|
|
|
System.out.print(BOLD + BLUE + "> " + RESET);
|
|
|
|
|
num = Integer.parseInt(scanner.nextLine());
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
System.out.println(RED + RESET + "请输入有效的数字:");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|