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.
56 lines
1.7 KiB
56 lines
1.7 KiB
package Program;
|
|
|
|
public class HighMaker extends QuestionMaker {
|
|
private static final char[] operators = {'+', '-', '*', '/'};
|
|
private static final String[] functions = {"sin", "cos", "tan"};
|
|
|
|
/**
|
|
* 为式子添加三角函数
|
|
* @return 添加三角函数后的式子
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected String makeOneQuestion() {
|
|
StringBuilder question = new StringBuilder();
|
|
boolean check=false;
|
|
|
|
int count=rand.nextInt(4)+2;
|
|
int trigFunction=rand.nextInt(count);
|
|
|
|
for(int i=0;i<count;i++){
|
|
if(i>0){
|
|
char operator=operators[rand.nextInt(operators.length)];
|
|
question.append(" ").append(operator).append(" ");
|
|
}
|
|
|
|
if(i==trigFunction&&!check){
|
|
String function=functions[rand.nextInt(functions.length)];
|
|
int angle=rand.nextInt(100);
|
|
question.append(function).append("(").append(angle).append(")");
|
|
check=true;
|
|
}else{
|
|
int random=randomMaker();
|
|
question.append(random);
|
|
}
|
|
}
|
|
|
|
if(!check){
|
|
String function=functions[rand.nextInt(functions.length)];
|
|
char operator=operators[rand.nextInt(operators.length)];
|
|
int angle=rand.nextInt(100);
|
|
question.append(" ").append(operator).append(" ").append(function)
|
|
.append("(").append(angle).append(")");
|
|
}
|
|
return question.toString();
|
|
}
|
|
|
|
@Override
|
|
|
|
protected boolean checkQuestion(String question) {
|
|
// 检查是否包含三角函数
|
|
return question.contains("sin(") || question.contains("cos(")
|
|
|| question.contains("tan(");
|
|
}
|
|
}
|