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.
40 lines
991 B
40 lines
991 B
package Generator;
|
|
|
|
import java.util.Random;
|
|
|
|
public class Pri_g_ques implements G_ques{
|
|
private Random ra= new Random();
|
|
|
|
@Override
|
|
public String g_question() {
|
|
int count=ra.nextInt(4)+2;
|
|
StringBuilder question = new StringBuilder();
|
|
int count_bracket=0;
|
|
for (int i=0;i<count;i++) {
|
|
if (i > 0) {
|
|
question.append(" ").append(g_operator()).append(" ");
|
|
}
|
|
if (i!=count-1&&ra.nextDouble()<0.4){
|
|
question.append("(");
|
|
count_bracket++;
|
|
}
|
|
question.append(ra.nextInt(100) + 1);
|
|
}
|
|
if (count_bracket!=0){
|
|
question.append(")".repeat(Math.max(0, count_bracket)));
|
|
}
|
|
return question.toString();
|
|
}
|
|
|
|
@Override
|
|
public String g_type(){
|
|
return "小学";
|
|
}
|
|
|
|
@Override
|
|
public char g_operator(){
|
|
char[] op={'+','-','*','/'};
|
|
return op[ra.nextInt(op.length)];
|
|
}
|
|
}
|