Compare commits
No commits in common. 'main' and 'develop' have entirely different histories.
@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: Main
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package account;
|
|
||||||
|
|
||||||
public class Account {
|
|
||||||
private String userName;
|
|
||||||
private String password;
|
|
||||||
private String userType;
|
|
||||||
|
|
||||||
public Account(String userName, String password,String userType) {
|
|
||||||
this.userName = userName;
|
|
||||||
this.password = password;
|
|
||||||
this.userType = userType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserType() {
|
|
||||||
return userType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserName() {
|
|
||||||
return userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserType(String userType) {
|
|
||||||
this.userType = userType;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package account;
|
|
||||||
|
|
||||||
public interface AccountService {
|
|
||||||
Account login(String username, String password);
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package account;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SimpleAccountService implements AccountService {
|
|
||||||
private static final Map<String, Account> accounts = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
accounts.put("张三1", new Account("张三1", "123", "小学"));
|
|
||||||
accounts.put("张三2", new Account("张三2", "123", "小学"));
|
|
||||||
accounts.put("张三3", new Account("张三3", "123", "小学"));
|
|
||||||
accounts.put("李四1", new Account("李四1", "123", "初中"));
|
|
||||||
accounts.put("李四2", new Account("李四2", "123", "初中"));
|
|
||||||
accounts.put("李四3", new Account("李四3", "123", "初中"));
|
|
||||||
accounts.put("王五1", new Account("王五1", "123", "高中"));
|
|
||||||
accounts.put("王五2", new Account("王五2", "123", "高中"));
|
|
||||||
accounts.put("王五3", new Account("王五3", "123", "高中"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Account login(String username, String password) {
|
|
||||||
Account account = accounts.get(username);
|
|
||||||
if (account != null && account.getPassword().equals(password)) {
|
|
||||||
return account;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
package persistence;
|
|
||||||
|
|
||||||
import question.Question;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FileSaver {
|
|
||||||
public static void saveQuestions(String username, List<Question> questions) {
|
|
||||||
File dir = new File(username);
|
|
||||||
if (!dir.exists()) dir.mkdirs();
|
|
||||||
|
|
||||||
String filename = LocalDateTime.now().format(
|
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")) + ".txt";
|
|
||||||
|
|
||||||
try (FileWriter writer = new FileWriter(new File(dir, filename))) {
|
|
||||||
for (int i = 0; i < questions.size(); i++) {
|
|
||||||
writer.write((i + 1) + ". " + questions.get(i).getQuestion() + "\n\n");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println("题目已生成并保存!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
package question;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class HighQuestionGenerator implements QuestionGenerator {
|
|
||||||
private static final Random random = new Random();
|
|
||||||
private final QuestionGenerator primaryGenerator = new PrimaryQuestionGenerator();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Question generateQuestion() {
|
|
||||||
Question q = primaryGenerator.generateQuestion();
|
|
||||||
String[] funcs = {"sin", "cos", "tan"};
|
|
||||||
String func = funcs[random.nextInt(funcs.length)];
|
|
||||||
return new Question(func + "(" + q.getQuestion() + ")", evaluate(func, q.getQuestion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String evaluate(String func, String expr) {
|
|
||||||
try {
|
|
||||||
javax.script.ScriptEngineManager mgr = new javax.script.ScriptEngineManager();
|
|
||||||
javax.script.ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
|
||||||
return String.valueOf(engine.eval("Math." + func + "(Math.toRadians(" + expr + "))"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "?";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package question;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class MiddleQuestionGenerator implements QuestionGenerator {
|
|
||||||
private static final Random random = new Random();
|
|
||||||
private final QuestionGenerator primaryGenerator = new PrimaryQuestionGenerator();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Question generateQuestion() {
|
|
||||||
Question q = primaryGenerator.generateQuestion();
|
|
||||||
if (random.nextBoolean()) {
|
|
||||||
return new Question(q.getQuestion() + " ^ 2", evaluate(q.getQuestion() + "^2"));
|
|
||||||
} else {
|
|
||||||
return new Question("√" + q.getQuestion(), evaluate("Math.sqrt(" + q.getQuestion() + ")"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String evaluate(String expr) {
|
|
||||||
try {
|
|
||||||
javax.script.ScriptEngineManager mgr = new javax.script.ScriptEngineManager();
|
|
||||||
javax.script.ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
|
||||||
return String.valueOf(engine.eval(expr.replace("^", "**")));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "?";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
package question;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class PrimaryQuestionGenerator implements QuestionGenerator {
|
|
||||||
private static final Random random = new Random();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Question generateQuestion() {
|
|
||||||
int numOperands = random.nextInt(5) + 1;
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
int currentValue = random.nextInt(100) + 1;
|
|
||||||
sb.append(currentValue);
|
|
||||||
|
|
||||||
for (int i = 1; i < numOperands; i++) {
|
|
||||||
String[] ops = {"+", "-", "*", "/"};
|
|
||||||
String op;
|
|
||||||
int nextVal;
|
|
||||||
do {
|
|
||||||
op = ops[random.nextInt(ops.length)];
|
|
||||||
nextVal = random.nextInt(100) + 1;
|
|
||||||
} while ((op.equals("-") && currentValue < nextVal) ||
|
|
||||||
(op.equals("/") && (nextVal == 0 || currentValue % nextVal != 0)));
|
|
||||||
|
|
||||||
sb.append(" ").append(op).append(" ").append(nextVal);
|
|
||||||
switch (op) {
|
|
||||||
case "+": currentValue += nextVal; break;
|
|
||||||
case "-": currentValue -= nextVal; break;
|
|
||||||
case "*": currentValue *= nextVal; break;
|
|
||||||
case "/": currentValue /= nextVal; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String expr = addParentheses(sb.toString());
|
|
||||||
return new Question(expr, evaluate(expr));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String addParentheses(String expr) {
|
|
||||||
String[] tokens = expr.split(" ");
|
|
||||||
if (tokens.length < 3) return expr;
|
|
||||||
|
|
||||||
int start = random.nextInt(tokens.length / 2) * 2;
|
|
||||||
int end = start + 2 + random.nextInt((tokens.length - start) / 2) * 2;
|
|
||||||
end = Math.min(end, tokens.length - 1);
|
|
||||||
|
|
||||||
StringBuilder newExpr = new StringBuilder();
|
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
|
||||||
if (i == start) newExpr.append("(");
|
|
||||||
newExpr.append(tokens[i]);
|
|
||||||
if (i == end) newExpr.append(")");
|
|
||||||
if (i != tokens.length - 1) newExpr.append(" ");
|
|
||||||
}
|
|
||||||
return newExpr.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String evaluate(String expr) {
|
|
||||||
try {
|
|
||||||
javax.script.ScriptEngineManager mgr = new javax.script.ScriptEngineManager();
|
|
||||||
javax.script.ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
|
||||||
return String.valueOf(engine.eval(expr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "?";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
package question;
|
|
||||||
|
|
||||||
public class Question {
|
|
||||||
private String question;
|
|
||||||
private String answer;
|
|
||||||
|
|
||||||
public Question(String question, String answer) {
|
|
||||||
this.question = question;
|
|
||||||
this.answer = answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQuestion() {
|
|
||||||
return question;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAnswer() {
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package question;
|
|
||||||
|
|
||||||
public interface QuestionGenerator {
|
|
||||||
Question generateQuestion();
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue