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.
TestPaperGenerationSystem/src/HighSchoolProblemGenerator....

36 lines
1.3 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 java.util.ArrayList;
import java.util.List;
/**
* 高中题目生成器(具体策略)。
* 它首先生成一个包含初中难度运算(平方/开方)的题目,
* 然后再额外加入一个三角函数运算,使得题目难度递增。
*/
public class HighSchoolProblemGenerator extends MiddleSchoolProblemGenerator {
private static final int[] PREDEFINED_ANGLES = {0, 30, 45, 60, 90};
private static final String[] TRIG_FUNCTIONS = {"sin", "cos", "tan"};
@Override
protected Equation createProblem() {
// 1. 调用父类(已修正的 MiddleSchoolProblemGenerator的方法
Equation middleSchoolEquation = super.createProblem();
List<String> operands = new ArrayList<>(middleSchoolEquation.getOperands());
List<Operator> operators = new ArrayList<>(middleSchoolEquation.getOperators());
// 2. 随机替换一个操作数为三角函数
int modifyIndex = random.nextInt(operands.size());
int angle = PREDEFINED_ANGLES[random.nextInt(PREDEFINED_ANGLES.length)];
String funcType = TRIG_FUNCTIONS[random.nextInt(TRIG_FUNCTIONS.length)];
if ("tan".equals(funcType) && angle == 90) {
angle = 45; // 避免 tan(90)
}
String trigExpression = String.format("%s(%d)", funcType, angle);
operands.set(modifyIndex, trigExpression);
return new Equation(operands, operators);
}
}