parent
1cb0f26bab
commit
232c548d77
@ -0,0 +1,40 @@
|
|||||||
|
import auth.AuthService;
|
||||||
|
import model.Level;
|
||||||
|
import model.User;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
private static final AuthService.TestPaperService testPaperService = new AuthService.TestPaperService();
|
||||||
|
private static User currentUser = null;
|
||||||
|
private static Level currentLevel = null;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
while (true) {
|
||||||
|
if (currentUser == null) {
|
||||||
|
handleLogin(scanner);
|
||||||
|
} else {
|
||||||
|
handleQuestionGeneration(scanner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleLogin(Scanner scanner) {
|
||||||
|
System.out.println("**********数学试卷生成项目**********");
|
||||||
|
System.out.println("请输入用户名和密码,用空格隔开:");
|
||||||
|
String[] input = scanner.nextLine().split(" ");
|
||||||
|
if (input.length == 2) {
|
||||||
|
authService.login(input[0], input[1]).ifPresentOrElse(
|
||||||
|
user -> {
|
||||||
|
currentUser = user;
|
||||||
|
currentLevel = user.getLevel();
|
||||||
|
System.out.printf("当前选择为%s出题%n", currentLevel.getName()); // 登录成功提示
|
||||||
|
},
|
||||||
|
() -> System.out.println("请输入正确的用户名、密码") // 登录失败提示
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
System.out.println("输入格式不正确,请重新输入。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package auth;
|
||||||
|
|
||||||
|
import model.Level;
|
||||||
|
import model.User;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AuthService {
|
||||||
|
private final List<User> users;
|
||||||
|
|
||||||
|
public AuthService() {
|
||||||
|
this.users = new ArrayList<>();
|
||||||
|
// 初始化用户账户
|
||||||
|
users.add(new User("张三1", "123", Level.ELEMENTARY));
|
||||||
|
users.add(new User("张三2", "123", Level.ELEMENTARY));
|
||||||
|
users.add(new User("张三3", "123", Level.ELEMENTARY));
|
||||||
|
users.add(new User("李四1", "123", Level.JUNIOR_HIGH));
|
||||||
|
users.add(new User("李四2", "123", Level.JUNIOR_HIGH));
|
||||||
|
users.add(new User("李四3", "123", Level.JUNIOR_HIGH));
|
||||||
|
users.add(new User("王五1", "123", Level.SENIOR_HIGH));
|
||||||
|
users.add(new User("王五2", "123", Level.SENIOR_HIGH));
|
||||||
|
users.add(new User("王五3", "123", Level.SENIOR_HIGH));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public enum Level {
|
||||||
|
ELEMENTARY("小学"),
|
||||||
|
JUNIOR_HIGH("初中"),
|
||||||
|
SENIOR_HIGH("高中");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
Level(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Level fromString(String text) {
|
||||||
|
for (Level b : Level.values()) {
|
||||||
|
if (b.name.equalsIgnoreCase(text)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
private final String username;
|
||||||
|
private final String password;
|
||||||
|
private final Level level;
|
||||||
|
|
||||||
|
public User(String username, String password, Level level) {
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Level getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue