Compare commits
2 Commits
df33ab2555
...
37e9a91704
Author | SHA1 | Date |
---|---|---|
|
37e9a91704 | 6 days ago |
|
6cc655468a | 6 days ago |
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,29 @@
|
|||||||
|
1. 58 =
|
||||||
|
|
||||||
|
2. 19 / 81 =
|
||||||
|
|
||||||
|
3. 77 - 20 =
|
||||||
|
|
||||||
|
4. (66 + 65 + 35 / 57) =
|
||||||
|
|
||||||
|
5. 29 / 37 =
|
||||||
|
|
||||||
|
6. (64 / 31) - 27 * 64 - 69 =
|
||||||
|
|
||||||
|
7. ((97) * 83 * 39 + 23) =
|
||||||
|
|
||||||
|
8. 72 - 85 =
|
||||||
|
|
||||||
|
9. 30 - 79 + 63 + 82 =
|
||||||
|
|
||||||
|
10. 95 - 26 =
|
||||||
|
|
||||||
|
11. 13 - 98 =
|
||||||
|
|
||||||
|
12. 36 - 55 =
|
||||||
|
|
||||||
|
13. (((94 + 72) * 1) * 13) / 90 =
|
||||||
|
|
||||||
|
14. 36 * 69 =
|
||||||
|
|
||||||
|
15. (68 + 60) * 65 / 33 =
|
@ -0,0 +1,31 @@
|
|||||||
|
1. 69 =
|
||||||
|
|
||||||
|
2. (4 + 49 - 36 + 79) =
|
||||||
|
|
||||||
|
3. 17 =
|
||||||
|
|
||||||
|
4. ((83 + 61 - 26) + 24 * 93) =
|
||||||
|
|
||||||
|
5. 65 =
|
||||||
|
|
||||||
|
6. 16 / 66 =
|
||||||
|
|
||||||
|
7. 5 / 93 =
|
||||||
|
|
||||||
|
8. 33 / 11 =
|
||||||
|
|
||||||
|
9. 91 =
|
||||||
|
|
||||||
|
10. (22 - 13) + 70 + 40 / 59 =
|
||||||
|
|
||||||
|
11. 88 =
|
||||||
|
|
||||||
|
12. ((87) + 89) - 55 * 76 =
|
||||||
|
|
||||||
|
13. 63 + 18 + 6 - 25 =
|
||||||
|
|
||||||
|
14. 44 / 37 - 45 - 87 =
|
||||||
|
|
||||||
|
15. ((74) + 53) / 31 / 54 =
|
||||||
|
|
||||||
|
16. 91 / 9 + 55 * 38 =
|
@ -0,0 +1,39 @@
|
|||||||
|
1. (9)² =
|
||||||
|
|
||||||
|
2. √99 =
|
||||||
|
|
||||||
|
3. (5)² =
|
||||||
|
|
||||||
|
4. √86 + (39) + 56 / 86 =
|
||||||
|
|
||||||
|
5. √44 + ((21) * 49) / 19 / 15 / 6 =
|
||||||
|
|
||||||
|
6. (4)² =
|
||||||
|
|
||||||
|
7. (7)² =
|
||||||
|
|
||||||
|
8. (5)² + (36 - 53 + 24) =
|
||||||
|
|
||||||
|
9. √27 =
|
||||||
|
|
||||||
|
10. (2)² =
|
||||||
|
|
||||||
|
11. (6)² + ((30) / 29 / 87) * 6 + 49 =
|
||||||
|
|
||||||
|
12. √54 =
|
||||||
|
|
||||||
|
13. √73 =
|
||||||
|
|
||||||
|
14. (5)² + 14 * 89 / 65 / 6 - 16 =
|
||||||
|
|
||||||
|
15. √55 =
|
||||||
|
|
||||||
|
16. √74 + (((16) - 29) * 26 - 34) =
|
||||||
|
|
||||||
|
17. √11 =
|
||||||
|
|
||||||
|
18. √41 + ((71) / 57 - 16 * 8) + 90 =
|
||||||
|
|
||||||
|
19. (6)² =
|
||||||
|
|
||||||
|
20. √63 =
|
@ -0,0 +1,39 @@
|
|||||||
|
1. sin(67°) + ((91) - 77) + 2 =
|
||||||
|
|
||||||
|
2. cos(40°) + (88) / 44 + 69 + 17 + 93 =
|
||||||
|
|
||||||
|
3. sin(20°) + 84 + 3 =
|
||||||
|
|
||||||
|
4. tan(16°) + 31 * 7 + 87 + 64 =
|
||||||
|
|
||||||
|
5. tan(18°) + (((24 - 34) - 27 * 58) * 67) =
|
||||||
|
|
||||||
|
6. cos(26°) + ((77 - 15 * 79) / 14 - 19) =
|
||||||
|
|
||||||
|
7. sin(24°) + 71 =
|
||||||
|
|
||||||
|
8. tan(14°) + 28 + 83 =
|
||||||
|
|
||||||
|
9. sin(7°) + (84) / 54 / 48 / 64 + 39 =
|
||||||
|
|
||||||
|
10. cos(21°) + 66 =
|
||||||
|
|
||||||
|
11. sin(33°) + 53 =
|
||||||
|
|
||||||
|
12. cos(37°) + 93 + 83 / 50 / 6 =
|
||||||
|
|
||||||
|
13. sin(38°) + (86 / 53 / 19 * 31) =
|
||||||
|
|
||||||
|
14. sin(48°) + 8 / 18 =
|
||||||
|
|
||||||
|
15. cos(83°) + 53 + 99 =
|
||||||
|
|
||||||
|
16. cos(73°) + 28 / 36 =
|
||||||
|
|
||||||
|
17. cos(10°) + 13 - 13 =
|
||||||
|
|
||||||
|
18. cos(83°) + 2 =
|
||||||
|
|
||||||
|
19. tan(35°) + (83) * 31 / 11 - 93 =
|
||||||
|
|
||||||
|
20. tan(26°) + (((53 + 63) + 74) + 22 / 58) =
|
@ -1,4 +0,0 @@
|
|||||||
public interface Question {
|
|
||||||
String generateQuestion();
|
|
||||||
boolean isValid();
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
import java.util.HashSet;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class QuestionGenerator {
|
|
||||||
private Random random;
|
|
||||||
private FileManager fileManager;
|
|
||||||
|
|
||||||
public QuestionGenerator() {
|
|
||||||
random = new Random();
|
|
||||||
fileManager = new FileManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] generateQuestions(DifficultyLevel level, int count, String username) {
|
|
||||||
Set<String> existingQuestions = fileManager.loadExistingQuestions(username);
|
|
||||||
Set<String> newQuestions = new HashSet<>();
|
|
||||||
String[] questions = new String[count];
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
String question;
|
|
||||||
int attempts = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
question = generateSingleQuestion(level, i + 1);
|
|
||||||
attempts++;
|
|
||||||
if (attempts > 100) {
|
|
||||||
return null; // 避免无限循环
|
|
||||||
}
|
|
||||||
} while (existingQuestions.contains(question) || newQuestions.contains(question));
|
|
||||||
|
|
||||||
newQuestions.add(question);
|
|
||||||
questions[i] = question;
|
|
||||||
}
|
|
||||||
|
|
||||||
return questions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateSingleQuestion(DifficultyLevel level, int questionNumber) {
|
|
||||||
int operandCount = random.nextInt(5) + 1; // 1-5个操作数
|
|
||||||
StringBuilder question = new StringBuilder(questionNumber + ". ");
|
|
||||||
|
|
||||||
switch (level) {
|
|
||||||
case PRIMARY:
|
|
||||||
question.append(generatePrimaryQuestion(operandCount));
|
|
||||||
break;
|
|
||||||
case JUNIOR:
|
|
||||||
question.append(generateJuniorQuestion(operandCount));
|
|
||||||
break;
|
|
||||||
case SENIOR:
|
|
||||||
question.append(generateSeniorQuestion(operandCount));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
question.append(" = ");
|
|
||||||
return question.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generatePrimaryQuestion(int operandCount) {
|
|
||||||
String[] operators = {"+", "-", "*", "/"};
|
|
||||||
StringBuilder question = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < operandCount; i++) {
|
|
||||||
if (i > 0) {
|
|
||||||
question.append(" ").append(operators[random.nextInt(operators.length)]).append(" ");
|
|
||||||
}
|
|
||||||
question.append(random.nextInt(100) + 1);
|
|
||||||
|
|
||||||
// 随机添加括号(小学难度)
|
|
||||||
if (operandCount > 2 && random.nextDouble() < 0.3) {
|
|
||||||
question.insert(0, "(").append(")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return question.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateJuniorQuestion(int operandCount) {
|
|
||||||
String question = generatePrimaryQuestion(operandCount);
|
|
||||||
|
|
||||||
// 确保至少有一个平方或开根号
|
|
||||||
if (random.nextBoolean()) {
|
|
||||||
return "√" + (random.nextInt(100) + 1) + " + " + question;
|
|
||||||
} else {
|
|
||||||
return "(" + (random.nextInt(10) + 1) + ")² + " + question;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateSeniorQuestion(int operandCount) {
|
|
||||||
String question = generatePrimaryQuestion(operandCount);
|
|
||||||
String[] trigFunctions = {"sin", "cos", "tan"};
|
|
||||||
|
|
||||||
// 确保至少有一个三角函数
|
|
||||||
return trigFunctions[random.nextInt(trigFunctions.length)] +
|
|
||||||
"(" + (random.nextInt(90) + 1) + "°) + " + question;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package factories;
|
||||||
|
|
||||||
|
import interfaces.LoginSystemInterface;
|
||||||
|
import interfaces.FileManagerInterface;
|
||||||
|
import services.LoginSystem;
|
||||||
|
import services.FileManager;
|
||||||
|
|
||||||
|
public class ServiceFactory {
|
||||||
|
public static LoginSystemInterface createLoginSystem() {
|
||||||
|
return new LoginSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileManagerInterface createFileManager() {
|
||||||
|
return new FileManager();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package interfaces;
|
||||||
|
|
||||||
|
import models.User;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface FileManagerInterface {
|
||||||
|
boolean saveQuestions(User user, String[] questions);
|
||||||
|
Set<String> loadExistingQuestions(String username);
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package interfaces;
|
||||||
|
|
||||||
|
import models.User;
|
||||||
|
import models.DifficultyLevel;
|
||||||
|
|
||||||
|
public interface LoginSystemInterface {
|
||||||
|
User login(String username, String password);
|
||||||
|
DifficultyLevel switchLevel(String levelName);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package interfaces;
|
||||||
|
|
||||||
|
import models.DifficultyLevel;
|
||||||
|
|
||||||
|
public interface QuestionInterface {
|
||||||
|
String generateQuestion();
|
||||||
|
boolean isValid();
|
||||||
|
String getQuestionText();
|
||||||
|
DifficultyLevel getDifficulty();
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
package models;
|
||||||
|
|
||||||
public enum DifficultyLevel {
|
public enum DifficultyLevel {
|
||||||
PRIMARY("小学"),
|
PRIMARY("小学"),
|
||||||
JUNIOR("初中"),
|
JUNIOR("初中"),
|
@ -0,0 +1,43 @@
|
|||||||
|
package services;
|
||||||
|
|
||||||
|
import interfaces.QuestionInterface;
|
||||||
|
import models.DifficultyLevel;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class QuestionGenerator {
|
||||||
|
private Random random;
|
||||||
|
private FileManager fileManager;
|
||||||
|
|
||||||
|
public QuestionGenerator() {
|
||||||
|
random = new Random();
|
||||||
|
fileManager = new FileManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] generateQuestions(DifficultyLevel level, int count, String username) {
|
||||||
|
Set<String> existingQuestions = fileManager.loadExistingQuestions(username);
|
||||||
|
Set<String> newQuestions = new HashSet<>();
|
||||||
|
String[] questions = new String[count];
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
QuestionInterface question;
|
||||||
|
int attempts = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
question = new MathQuestion(level);
|
||||||
|
attempts++;
|
||||||
|
if (attempts > 100) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} while (existingQuestions.contains(question.getQuestionText()) ||
|
||||||
|
newQuestions.contains(question.getQuestionText()) ||
|
||||||
|
!question.isValid());
|
||||||
|
|
||||||
|
newQuestions.add(question.getQuestionText());
|
||||||
|
questions[i] = (i + 1) + ". " + question.getQuestionText();
|
||||||
|
}
|
||||||
|
|
||||||
|
return questions;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in new issue