|
|
import java.util.Scanner;
|
|
|
|
|
|
public class MathApp {
|
|
|
private static LoginService loginService;
|
|
|
private static Scanner scanner = new Scanner(System.in);
|
|
|
private static String currentType = "小学"; // 默认账户类型是 "小学"
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
AccountService accountService = new AccountServiceImpl();
|
|
|
accountService.setAccounts(currentType);
|
|
|
|
|
|
loginService = new LoginServiceImpl(accountService);
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
login();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void login() {
|
|
|
|
|
|
System.out.print("请输入用户名和密码(空格隔开):");
|
|
|
String input = scanner.nextLine();
|
|
|
|
|
|
|
|
|
String[] credentials = input.split(" ");
|
|
|
|
|
|
if (credentials.length != 2) {
|
|
|
System.out.println("格式错误,请重新输入!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
String username = credentials[0].trim();
|
|
|
String password = credentials[1].trim();
|
|
|
|
|
|
if (loginService.authenticate(username, password)) {
|
|
|
System.out.println("登录成功!");
|
|
|
|
|
|
|
|
|
System.out.println("当前选择为 " + currentType + " 出题");
|
|
|
|
|
|
|
|
|
generateQuestions();
|
|
|
} else {
|
|
|
System.out.println("用户名或密码错误,请重新输入!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void generateQuestions() {
|
|
|
System.out.print("请输入生成题目数量(输入-1退出登录):");
|
|
|
int numQuestions = scanner.nextInt();
|
|
|
scanner.nextLine();
|
|
|
|
|
|
if (numQuestions == -1) {
|
|
|
System.out.println("退出登录!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (numQuestions < 10 || numQuestions > 30) {
|
|
|
System.out.println("请输入有效的题目数量(10-30)!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
System.out.println("生成 " + numQuestions + " 道题目...");
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void switchAccountType() {
|
|
|
System.out.print("请输入要切换的账户类型(小学、初中或高中):");
|
|
|
String type = scanner.nextLine().trim();
|
|
|
|
|
|
if (type.equals("小学") || type.equals("初中") || type.equals("高中")) {
|
|
|
currentType = type;
|
|
|
AccountService accountService = new AccountServiceImpl();
|
|
|
accountService.setAccounts(currentType);
|
|
|
|
|
|
loginService = new LoginServiceImpl(accountService);
|
|
|
|
|
|
System.out.println("系统提示:准备生成 " + currentType + " 数学题目,请输入生成题目数量");
|
|
|
} else {
|
|
|
System.out.println("请输入小学、初中和高中三个选项中的一个");
|
|
|
}
|
|
|
}
|
|
|
}
|