添加函数注释

pull/3/head
smallbailangui 7 months ago
parent cbd4efd7b5
commit 8c51ab9626

@ -15,6 +15,7 @@ public class Authenticator {
/**
*
* @return UserMap
*/
private static Map<String, User> initializeUsers() {
return Stream.of(

@ -11,6 +11,15 @@ import java.util.regex.Pattern;
* ()
*/
public class JuniorHighSchoolGenerator extends PrimarySchoolGenerator {
/**
*
* <p>
* PrimarySchoolGenerator
*
* x²x
*
* @return
*/
@Override
public String generateSingleQuestion() {
// 1. 先生成一个完整的小学难度题目(包含括号等)

@ -12,7 +12,15 @@ import java.util.concurrent.ThreadLocalRandom;
public class PrimarySchoolGenerator implements QuestionGenerator {
private static final String[] OPERATORS = {"+", "-", "*", "/"};
/**
*
* <p>
* 251-100
* "+", "-", "*", "/"
*
*
* @return
*/
@Override
public String generateSingleQuestion() {
ThreadLocalRandom random = ThreadLocalRandom.current();

@ -12,7 +12,16 @@ import java.util.regex.Pattern;
*/
public class SeniorHighSchoolGenerator extends JuniorHighSchoolGenerator { // <-- 关键改动:继承自初中生成器
private static final String[] TRIG_FUNCTIONS = {"sin", "cos", "tan"};
/**
*
* <p>
* JuniorHighSchoolGenerator
* /
*
* sin(), cos(), tan()
*
* @return
*/
@Override
public String generateSingleQuestion() {
// 1. 先生成一个完整的初中难度题目(已包含小学内容和平方/开根号)

@ -9,11 +9,19 @@ public enum Level {
SENIOR_HIGH("高中");
private final String chineseName;
/**
*
*
* @param chineseName
*/
Level(String chineseName) {
this.chineseName = chineseName;
}
/**
*
*
* @return
*/
public String getChineseName() {
return chineseName;
}

@ -17,12 +17,32 @@ public class PaperService {
private final FileManager fileManager;
private final PaperStrategy paperStrategy; // 持有策略接口的引用
// 通过构造函数注入具体的策略实现
/**
* PaperService
* <p>
*
* DI
*
* @param fileManager FileManager
* @param paperStrategy PaperStrategy
*/
public PaperService(FileManager fileManager, PaperStrategy paperStrategy) {
this.fileManager = fileManager;
this.paperStrategy = paperStrategy;
}
/**
*
* <p>
* orchestrates
* 1.
* 2. {@link PaperStrategy}
* 3.
* 4. {@link FileManager}
*
* @param user
* @param count
* @param currentLevel
*/
public void createAndSavePaper(User user, int count, Level currentLevel) {
Set<String> existingQuestions = fileManager.loadExistingQuestions(user.username());
List<String> newPaper = new ArrayList<>();

@ -6,6 +6,8 @@ import java.util.concurrent.ThreadLocalRandom;
/**
*
* <p>
*
*/
public class MixedDifficultyStrategy implements PaperStrategy {
// 策略内部持有所有可能的生成器

@ -8,5 +8,11 @@ import com.mathgenerator.model.Level;
*
*/
public interface PaperStrategy {
/**
*
*
* @param mainLevel
* @return QuestionGenerator
*/
QuestionGenerator selectGenerator(Level mainLevel);
}

@ -69,7 +69,10 @@ public class FileManager {
return new HashSet<>();
}
}
/**
* @param file (Path)
* @return (Stream) I/O
*/
private Stream<String> readQuestionsFromFile(Path file) {
try {
//TODO:这里需要修改警告:(72, 26) 在没有 'try-with-resources' 语句的情况下使用 'Stream<String>'

@ -16,7 +16,14 @@ public class ConsoleUI {
private final Authenticator authenticator;
private final PaperService paperService;
// 通过构造函数接收依赖的服务,这是一种常见的设计模式(依赖注入)
/**
* ConsoleUI
*
* 使UI使
*
* @param authenticator
* @param paperService
*/
public ConsoleUI(Authenticator authenticator, PaperService paperService) {
this.authenticator = authenticator;
this.paperService = paperService;
@ -32,7 +39,11 @@ public class ConsoleUI {
userOptional.ifPresent(this::showUserMenu);
}
}
/**
*
*
* @return OptionalOptional
*/
private Optional<User> handleLogin() {
printHeader("用户登录"); // 统一标题格式
System.out.print("请输入用户名和密码 (用空格隔开): (输入 exit 退出程序)\n> ");
@ -55,7 +66,11 @@ public class ConsoleUI {
}
return userOptional;
}
/**
*
*
* @param user
*/
private void showUserMenu(User user) {
Level currentLevel = user.level();
System.out.println("\n登录成功! 欢迎 " + user.username());
@ -88,7 +103,10 @@ public class ConsoleUI {
}
/**
*
*
*
* @param currentLevel
* @return
*/
private Level handleLevelSwitchMenu(Level currentLevel) {
while (true) { // <-- 增加循环
@ -120,7 +138,12 @@ public class ConsoleUI {
}
}
}
/**
*
*
* @param user
* @param currentLevel
*/
private void handleGeneration(User user, Level currentLevel) {
printHeader("生成 " + currentLevel.getChineseName() + " 题目");
System.out.print("请输入生成题目数量 (10-30输入 0 返回主菜单): ");
@ -139,13 +162,19 @@ public class ConsoleUI {
System.out.println("输入无效,请输入一个有效的数字。");
}
}
/**
*
*
* @param title
*/
private void printHeader(String title) {
printSeparator();
System.out.println(title);
printSeparator();
}
/**
* 线
*/
private void printSeparator() {
System.out.println("======================================================");
}

Loading…
Cancel
Save