|
|
|
|
@ -1,5 +1,11 @@
|
|
|
|
|
package src;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class JuniorTea extends Teacher{
|
|
|
|
|
public JuniorTea(String name, String password) {
|
|
|
|
|
super(name, password);
|
|
|
|
|
@ -7,7 +13,62 @@ public class JuniorTea extends Teacher{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String GenerateEX(int num, int type){
|
|
|
|
|
return null;
|
|
|
|
|
// 生成题目存储路径
|
|
|
|
|
Path filePath = Paths.get(super.generatePath());
|
|
|
|
|
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
String[] operators = {"+", "-", "*", "/", "^2", "√"};
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<num; i++){
|
|
|
|
|
int operandCount = random.nextInt(4) + 2;
|
|
|
|
|
StringBuilder question = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
int[] operands = new int[operandCount];
|
|
|
|
|
for(int j=0; j<operandCount; j++){
|
|
|
|
|
operands[j] = random.nextInt(100) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 随机决定是否以及在哪里加括号 (对于3个以上操作数)
|
|
|
|
|
boolean useParentheses = operandCount > 2 && random.nextBoolean();
|
|
|
|
|
int parenStartIndex = 0;
|
|
|
|
|
if (useParentheses) {
|
|
|
|
|
parenStartIndex = random.nextInt(operandCount - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < operandCount; j++) {
|
|
|
|
|
if (useParentheses && j == parenStartIndex) {
|
|
|
|
|
question.append("(");
|
|
|
|
|
}
|
|
|
|
|
question.append(operands[j]);
|
|
|
|
|
if (useParentheses && j == parenStartIndex + 1) {
|
|
|
|
|
question.append(")");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(j < operandCount - 1){
|
|
|
|
|
String op = operators[random.nextInt(operators.length)];
|
|
|
|
|
|
|
|
|
|
// 避免除以0
|
|
|
|
|
if (op == "/" && operands[j+1] == 0) {
|
|
|
|
|
operands[j+1] = random.nextInt(100) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
question.append(" " + op + " " );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String qstr = "(" + (i+1) + ")" + question.toString() + " =\n";
|
|
|
|
|
// 题目查重
|
|
|
|
|
if(super.checkDuplicate(qstr)){
|
|
|
|
|
i--;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 写入文档
|
|
|
|
|
try {
|
|
|
|
|
java.nio.file.Files.writeString(filePath, qstr, StandardOpenOption.APPEND);
|
|
|
|
|
} catch (IOException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return filePath.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|