diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..b9d18bf --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..ff7987a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/JuniorQuestionGenerator.class b/src/JuniorQuestionGenerator.class index 754cb5e..a579601 100644 Binary files a/src/JuniorQuestionGenerator.class and b/src/JuniorQuestionGenerator.class differ diff --git a/src/JuniorQuestionGenerator.java b/src/JuniorQuestionGenerator.java index e18a9c1..88880d8 100644 --- a/src/JuniorQuestionGenerator.java +++ b/src/JuniorQuestionGenerator.java @@ -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(" = ?"); diff --git a/src/PrimaryQuestionGenerator.class b/src/PrimaryQuestionGenerator.class index cd819b7..06444b5 100644 Binary files a/src/PrimaryQuestionGenerator.class and b/src/PrimaryQuestionGenerator.class differ diff --git a/src/PrimaryQuestionGenerator.java b/src/PrimaryQuestionGenerator.java index 10887e0..ef1c2e4 100644 --- a/src/PrimaryQuestionGenerator.java +++ b/src/PrimaryQuestionGenerator.java @@ -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(" = ?"); diff --git a/src/SeniorQuestionGenerator.class b/src/SeniorQuestionGenerator.class index 4b290f3..a25a976 100644 Binary files a/src/SeniorQuestionGenerator.class and b/src/SeniorQuestionGenerator.class differ diff --git a/src/SeniorQuestionGenerator.java b/src/SeniorQuestionGenerator.java index 0444394..28e076a 100644 --- a/src/SeniorQuestionGenerator.java +++ b/src/SeniorQuestionGenerator.java @@ -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(" = ?");