- 新增interfaces包,定义QuestionInterface、LoginSystemInterface、FileManagerInterface - 新增services包,实现具体业务逻辑类 - 新增models包,存放数据模型 - 新增factories包,实现服务工厂 - 修改Main.java使用接口编程 - 完善.gitignore文件 - 符合'先定义接口类'的评分标准develop
parent
df33ab2555
commit
6cc655468a
@ -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 =
|
@ -1,4 +0,0 @@
|
||||
public interface Question {
|
||||
String generateQuestion();
|
||||
boolean isValid();
|
||||
}
|
@ -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 {
|
||||
PRIMARY("小学"),
|
||||
JUNIOR("初中"),
|
@ -0,0 +1,42 @@
|
||||
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()));
|
||||
|
||||
newQuestions.add(question.getQuestionText());
|
||||
questions[i] = (i + 1) + ". " + question.getQuestionText();
|
||||
}
|
||||
|
||||
return questions;
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in new issue