Merge pull request '123' (#6) from develop into main

main
hnu202326010306 2 days ago
commit fb138aa918

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="GoogleStyle" />
</state>
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/张三1/2025-09-28-21-31-14.txt" charset="GBK" />
</component>
</project>

Binary file not shown.

@ -7,27 +7,46 @@ import java.util.Random;
public class JuniorQuestionGenerator implements QuestionGenerator {
@Override
public String generateQuestion(StringBuilder question, Random random) {
// 确保所有初中题目都包含至少一个平方或开根号的运算符
int num = random.nextInt(100) + 1;
boolean isSquare = random.nextBoolean();
if (isSquare) {
// 生成平方题
question.append(num).append("^2");
} else {
// 生成开根号题,确保是完全平方数
int sqrtNum = random.nextInt(10) + 1;
num = sqrtNum * sqrtNum;
question.append("√").append(num);
// 随机生成1-5个操作数
int operandCount = random.nextInt(5) + 1;
String[] operators = {"+", "-", "*"};
String[] chosenOperators = new String[operandCount - 1];
// 确定包含平方或开根号的操作数位置
int specialPosition = random.nextInt(operandCount);
// 生成所有操作数
for (int i = 0; i < operandCount; i++) {
if (i == specialPosition) {
// 特殊操作数:平方或开根号
boolean isSquare = random.nextBoolean();
int num = random.nextInt(100) + 1;
if (isSquare) {
// 生成平方题
question.append(num).append("^2");
} else {
// 生成开根号题,确保是完全平方数
int sqrtNum = random.nextInt(10) + 1;
num = sqrtNum * sqrtNum;
question.append("√").append(num);
}
} else {
// 普通操作数
int num = random.nextInt(100) + 1;
question.append(num);
}
// 添加运算符(除了最后一个操作数)
if (i < operandCount - 1) {
chosenOperators[i] = operators[random.nextInt(operators.length)];
question.append(" " + chosenOperators[i] + " ");
}
}
// 添加一些其他运算符使题目更复杂
int complexity = random.nextInt(2) + 1;
for (int i = 0; i < complexity; i++) {
String[] operators = {"+", "-", "*"};
String op = operators[random.nextInt(operators.length)];
int addNum = random.nextInt(10) + 1;
question.append(" ").append(op).append(" ").append(addNum);
// 10%的概率添加外层括号(如果有多个操作数)
if (operandCount > 1 && random.nextDouble() < 0.1) {
question.insert(0, "(").append(")");
}
question.append(" = ?");

@ -7,32 +7,53 @@ import java.util.Random;
public class PrimaryQuestionGenerator implements QuestionGenerator {
@Override
public String generateQuestion(StringBuilder question, Random random) {
int num1 = random.nextInt(100) + 1; // 1-100的随机数
int num2 = random.nextInt(100) + 1;
// 随机生成1-5个操作
int operandCount = random.nextInt(5) + 1;
String[] operators = {"+", "-", "*", "/"};
String op = operators[random.nextInt(operators.length)];
int[] operands = new int[operandCount];
String[] chosenOperators = new String[operandCount - 1];
// 确保减法和除法结果为正整数
if ("-".equals(op) && num1 < num2) {
int temp = num1;
num1 = num2;
num2 = temp;
} else if ("/".equals(op)) {
// 生成第一个操作数
operands[0] = random.nextInt(100) + 1; // 1-100的随机数
question.append(operands[0]);
// 生成剩余的操作数和运算符
for (int i = 1; i < operandCount; i++) {
chosenOperators[i-1] = operators[random.nextInt(operators.length)];
operands[i] = random.nextInt(100) + 1;
// 确保减法结果非负
if ("-".equals(chosenOperators[i-1]) && operands[i-1] < operands[i]) {
// 如果当前操作数小于下一个操作数,交换它们
int temp = operands[i-1];
operands[i-1] = operands[i];
operands[i] = temp;
// 更新已添加到问题中的数值
question.setLength(0);
question.append(operands[0]);
for (int j = 1; j < i; j++) {
question.append(" " + chosenOperators[j-1] + " " + operands[j]);
}
}
// 确保除法结果为整数
num1 = num2 * (random.nextInt(10) + 1);
else if ("/".equals(chosenOperators[i-1])) {
// 调整被除数为除数的倍数
operands[i-1] = operands[i] * (random.nextInt(10) + 1);
// 更新已添加到问题中的数值
question.setLength(0);
question.append(operands[0]);
for (int j = 1; j < i; j++) {
question.append(" " + chosenOperators[j-1] + " " + operands[j]);
}
}
// 添加运算符和操作数
question.append(" " + chosenOperators[i-1] + " " + operands[i]);
}
// 10%的概率添加括号
if (random.nextDouble() < 0.1) {
question.append("(");
question.append(num1);
question.append(" ").append(op).append(" ");
question.append(num2);
question.append(")");
} else {
question.append(num1);
question.append(" ").append(op).append(" ");
question.append(num2);
// 10%的概率添加外层括号(如果有多个操作数)
if (operandCount > 1 && random.nextDouble() < 0.1) {
question.insert(0, "(").append(")");
}
question.append(" = ?");

Binary file not shown.

@ -7,20 +7,37 @@ import java.util.Random;
public class SeniorQuestionGenerator implements QuestionGenerator {
@Override
public String generateQuestion(StringBuilder question, Random random) {
// 确保所有高中题目都包含至少一个sin、cos或tan的运算符
String[] functions = {"sin(", "cos(", "tan("};
String func = functions[random.nextInt(functions.length)];
int angle = random.nextInt(100)+1;
question.append(func).append(angle).append(")");
// 随机生成1-5个操作数
int operandCount = random.nextInt(5) + 1;
String[] operators = {"+", "-", "*", "/"};
// 确定包含三角函数的操作数位置
int trigPosition = random.nextInt(operandCount);
// 生成所有操作数
for (int i = 0; i < operandCount; i++) {
if (i == trigPosition) {
// 三角函数操作数
String[] trigFunctions = {"sin", "cos", "tan"};
String function = trigFunctions[random.nextInt(trigFunctions.length)];
int num = random.nextInt(100) + 1;
question.append(function).append("(").append(num).append(")");
} else {
// 普通操作数
int num = random.nextInt(100) + 1;
question.append(num);
}
// 添加运算符(除了最后一个操作数)
if (i < operandCount - 1) {
String op = operators[random.nextInt(operators.length)];
question.append(" " + op + " ");
}
}
// 添加一些其他运算符使题目更复杂
int complexity = random.nextInt(3);
for (int i = 0; i < complexity; i++) {
String[] operators = {"+", "-", "*", "/"};
String op = operators[random.nextInt(operators.length)];
int num = random.nextInt(10) + 1;
question.append(" ").append(op).append(" " ).append(num);
// 10%的概率添加外层括号(如果有多个操作数)
if (operandCount > 1 && random.nextDouble() < 0.1) {
question.insert(0, "(").append(")");
}
question.append(" = ?");

Loading…
Cancel
Save