|
|
|
@ -35,9 +35,9 @@ public class Main {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
initAccounts();
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
|
|
|
|
|
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
|
|
|
|
|
while (true) {
|
|
|
|
|
Account login = loginLoop(reader);
|
|
|
|
|
Account login = loginLoop(scanner);
|
|
|
|
|
if (login == null) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -46,7 +46,7 @@ public class Main {
|
|
|
|
|
// 登录后的工作循环
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.println("准备生成" + currentLevel + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录)");
|
|
|
|
|
String line = readLineTrim(reader);
|
|
|
|
|
String line = readLineTrim(scanner);
|
|
|
|
|
if (line == null) return; // EOF
|
|
|
|
|
// 支持命令:切换为XX
|
|
|
|
|
if (line.startsWith("切换为")) {
|
|
|
|
@ -103,14 +103,15 @@ public class Main {
|
|
|
|
|
USER_MAP.put("王五3", new Account("王五3", "123", Level.高中));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Account loginLoop(BufferedReader reader) {
|
|
|
|
|
private static Account loginLoop(Scanner scanner) {
|
|
|
|
|
System.out.println("请输入用户名和密码(用空格分隔),或输入-1退出:");
|
|
|
|
|
while (true) {
|
|
|
|
|
System.out.println("请输入用户名和密码(用空格分隔),或按Ctrl+D退出:");
|
|
|
|
|
String line = readLineTrim(reader);
|
|
|
|
|
String line = readLineTrim(scanner);
|
|
|
|
|
if (line == null) return null; // EOF 退出
|
|
|
|
|
if ("-1".equals(line)) return null; // 主动输入-1退出
|
|
|
|
|
String[] parts = line.split("\\s+");
|
|
|
|
|
if (parts.length != 2) {
|
|
|
|
|
System.out.println("请按格式输入");
|
|
|
|
|
System.out.println("请输入正确的用户名、密码,或输入-1退出");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String username = parts[0];
|
|
|
|
@ -119,18 +120,15 @@ public class Main {
|
|
|
|
|
if (acc != null && Objects.equals(acc.password, password)) {
|
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("请输入正确的用户名、密码");
|
|
|
|
|
System.out.println("请输入正确的用户名、密码,或输入-1退出");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String readLineTrim(BufferedReader reader) {
|
|
|
|
|
try {
|
|
|
|
|
String s = reader.readLine();
|
|
|
|
|
if (s == null) return null;
|
|
|
|
|
return s.trim();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
private static String readLineTrim(Scanner scanner) {
|
|
|
|
|
if (!scanner.hasNextLine()) return null;
|
|
|
|
|
String s = scanner.nextLine();
|
|
|
|
|
if (s == null) return null;
|
|
|
|
|
return s.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Level parseLevel(String s) {
|
|
|
|
|