You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import Base.User;
import Deal.Deal_paper;
import Deal.Deal_user;
import java.util.Scanner;
public class Math_System {
private User now_user;
private Deal_paper d_paper;
private Deal_user d_user;
private Scanner scanner;
public Math_System(){
now_user=null;
d_paper=null;
d_user=new Deal_user();
}
public void main_menu(){
scanner=new Scanner(System.in);
while(true){
if (now_user==null){
login_in();
}
else {
generator();
}
}
}
public void login_in(){
System.out.println("请输入用户名和密码(空格分隔):");
String input = scanner.nextLine().trim();
if (input.equalsIgnoreCase("exit")) {
System.exit(0);
}
String[] parts = input.split("\\s+"); //空格
if (parts.length != 2){
System.out.println("请输入正确的用户名、密码");
return;
}
String username=parts[0];
String psw=parts[1];
if (d_user.login(username,psw)==null) {
now_user=null;
System.out.println("请输入正确的用户名、密码");
}
else {
now_user=d_user.login(username,psw);
d_paper=new Deal_paper(now_user);
System.out.println("当前选择为 " + now_user.getUserType() + " 出题");
}
}
public void generator(){
System.out.println("准备生成"+now_user.getUserType()+"数学题目,请输入生成题目数量(输入-1将退出当前用户重新登录");
String input = scanner.nextLine().trim();
if (input.equals("-1")){
now_user=null;
d_paper=null;
return;
}
if (input.startsWith("切换为")) {
change_mode(input);
return;
}
try {
int count = Integer.parseInt(input);
if (count<10||count>30){
System.out.println("题目数量应在10-30之间。");
return;
}
d_paper.g_paper(count,now_user.getUsername());
}catch (NumberFormatException e){
System.out.println("请正确输入题目数量。");
}
}
public void change_mode(String new_mode){
String[] parts=new_mode.split("切换为");
String type=parts[1].trim();
if ((!type.equals("小学") && !type.equals("初中") && !type.equals("高中")) || parts.length!=2){
System.out.println("请输入小学、初中和高中三个选项中的一个");
}
else{
now_user.change_type(type);
d_paper=new Deal_paper(now_user);
System.out.println("成功切换为"+type);
}
}
}