package model; public class HighMaker extends Student { final static String[] binaryOps = {"+", "-", "*", "/"}; // 操作符 final static String[] trigOps = {"sin", "cos", "tan"}; int operandCount; String[] questionParts; // 操作数 boolean[] specialOpFlags; // 特殊操作符索引序列 int parenStart; int parenEnd; public HighMaker(String name, String password, String path) { super(name, password, path); } // 数据预处理 public void getRandom() { this.operandCount = random.nextInt(4) + 2; this.questionParts = new String[this.operandCount]; // 使用基类方法随机决定特殊操作符的数量和位置 this.specialOpFlags = randomMaker(this.operandCount); // 生成题目各部分 for (int i = 0; i < operandCount; i++) { int operand = random.nextInt(100) + 1; if (specialOpFlags[i]) { String op = trigOps[random.nextInt(trigOps.length)]; questionParts[i] = op + "(" + operand + ")"; } else { questionParts[i] = String.valueOf(operand); } } // 使用基类方法生成有效括号 int[] parenPos = bracketMaker(this.operandCount); this.parenStart = parenPos[0]; this.parenEnd = parenPos[1]; } @Override protected String makeOneQuestion() { getRandom(); StringBuilder question = new StringBuilder(); for (int i = 0; i < operandCount; i++) { if (i == parenStart) { question.append("("); } question.append(questionParts[i]); if (i == parenEnd) { question.append(")"); } if (i < operandCount - 1) { String op = binaryOps[random.nextInt(binaryOps.length)]; question.append(" ").append(op).append(" "); } } return question.toString(); } }