forked from pnl4utw52/Math_Learning
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.
65 lines
1.8 KiB
65 lines
1.8 KiB
package Generator;
|
|
|
|
import java.util.Random;
|
|
|
|
public class Sen_g_ques implements G_ques{
|
|
private Random ra= new Random();
|
|
|
|
@Override
|
|
public String g_question() {
|
|
int count=ra.nextInt(5)+1;
|
|
StringBuilder question = new StringBuilder();
|
|
for (int i=0;i<count;i++) {
|
|
if (i > 0) {
|
|
question.append(" ").append(g_operator()).append(" ");
|
|
}
|
|
if (ra.nextDouble()<0.3){
|
|
question.append(g_trig()).append("²").append("(").append(g_angle()).append("°)");
|
|
}
|
|
else {
|
|
question.append(g_trig()).append("(").append(g_angle()).append("°)");
|
|
}
|
|
}
|
|
return add_brackets(question,count);
|
|
}
|
|
|
|
@Override
|
|
public String g_type(){
|
|
return "高中";
|
|
}
|
|
|
|
@Override
|
|
public char g_operator(){
|
|
char[] op={'+','-','*','/'};
|
|
return op[ra.nextInt(op.length)];
|
|
}
|
|
|
|
public String g_trig(){
|
|
String[] trig={"sin","cos","tan"};
|
|
return trig[ra.nextInt(trig.length)];
|
|
}
|
|
|
|
public String g_angle(){
|
|
String[] angle={"15","22.5","75","105","120","135","150","210","300"};
|
|
return angle[ra.nextInt(angle.length)];
|
|
}
|
|
|
|
public String add_brackets(StringBuilder s,int count){
|
|
String res=s.toString();
|
|
String[] parts=s.toString().split(" ");
|
|
if (ra.nextBoolean()&&parts.length!=1) {
|
|
int num=ra.nextInt(3)+1;
|
|
for (int i=0;i<num;i++) {
|
|
int pos = ra.nextInt(count);
|
|
if (pos==count-1){
|
|
pos=pos-1;
|
|
}
|
|
parts[pos * 2] = "(" + parts[pos * 2];
|
|
parts[parts.length-1]=parts[parts.length-1]+")";
|
|
}
|
|
res = String.join(" ", parts);
|
|
}
|
|
return res;
|
|
}
|
|
}
|