Compare commits
40 Commits
759da7ea69
...
1b195fb517
@ -0,0 +1,138 @@
|
||||
// Highproblem.java
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 高中数学题目生成器实现类。
|
||||
*/
|
||||
public class HighSchoolProblemGenerator implements MathProblemGenerator {
|
||||
private static final Random random = new Random();
|
||||
private static int advancedOperationFlag = 1;
|
||||
private String userName = "default";
|
||||
private String timestamp = "default";
|
||||
private int problemNumber = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int index = 0; index < 15; index++) {
|
||||
advancedOperationFlag = 1;
|
||||
HighSchoolProblemGenerator generator = new HighSchoolProblemGenerator();
|
||||
System.out.println((index + 1) + ". " + generator.generateSmartExpression());
|
||||
}
|
||||
}
|
||||
|
||||
public void start(int problemCount, String userName) {
|
||||
this.userName = userName;
|
||||
TimeManager timeManager = new TimeManager();
|
||||
timestamp = timeManager.getCurrentTime();
|
||||
|
||||
for (int index = 0; index < problemCount; index++) {
|
||||
advancedOperationFlag = 1;
|
||||
System.out.println((index + 1) + ". " + generateSmartExpression());
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSmartExpression() {
|
||||
int operatorCount = random.nextInt(3) + 1;
|
||||
int advancedOperationTarget = random.nextInt(operatorCount) + 1;
|
||||
String result;
|
||||
|
||||
while (true) {
|
||||
boolean isDuplicate = false;
|
||||
result = buildExpression(operatorCount, advancedOperationTarget);
|
||||
|
||||
FileManager fileManager = new FileManager();
|
||||
fileManager.readUserFiles(userName);
|
||||
|
||||
for (String line : fileManager.getFileLines()) {
|
||||
String[] parts = line.split("\\.", 2);
|
||||
String expression = parts.length > 1 ? parts[1] : line;
|
||||
if (result.equals(expression)) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDuplicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fileManager.createUserFile(userName, timestamp);
|
||||
fileManager.writeToFile(userName, timestamp, problemNumber + "." + result);
|
||||
fileManager.writeToFile(userName, timestamp, " ");
|
||||
problemNumber++;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildExpression(int operatorCount, int advancedOperationTarget) {
|
||||
if (operatorCount == 1) {
|
||||
return generateSimpleExpression(advancedOperationTarget);
|
||||
}
|
||||
|
||||
int splitPoint = random.nextInt(operatorCount - 1) + 1;
|
||||
|
||||
String leftPart = (splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(splitPoint, advancedOperationTarget) + ")"
|
||||
: buildExpression(splitPoint, advancedOperationTarget);
|
||||
|
||||
String rightPart = (operatorCount - splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(operatorCount - splitPoint, advancedOperationTarget) + ")"
|
||||
: buildExpression(operatorCount - splitPoint, advancedOperationTarget);
|
||||
|
||||
char operator = getRandomOperator("+-*/");
|
||||
return leftPart + " " + operator + " " + rightPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSimpleExpression(int advancedOperationTarget) {
|
||||
int firstOperand = random.nextInt(100) + 1;
|
||||
int secondOperand = random.nextInt(100) + 1;
|
||||
char operator = getRandomOperator("+-*/√²123");
|
||||
|
||||
if (advancedOperationFlag == advancedOperationTarget) {
|
||||
operator = getRandomOperator("123");
|
||||
if (operator == '1') {
|
||||
advancedOperationFlag = 0;
|
||||
return "sin" + secondOperand + "°";
|
||||
} else if (operator == '2') {
|
||||
advancedOperationFlag = 0;
|
||||
return "cos" + secondOperand + "°";
|
||||
} else if (operator == '3') {
|
||||
advancedOperationFlag = 0;
|
||||
return "tan" + secondOperand + "°";
|
||||
}
|
||||
} else {
|
||||
advancedOperationFlag++;
|
||||
}
|
||||
|
||||
if (random.nextInt(2) == 0) {
|
||||
return firstOperand + "";
|
||||
}
|
||||
|
||||
if (operator == '√') {
|
||||
return operator + "" + secondOperand;
|
||||
} else if (operator == '1') {
|
||||
return "sin" + secondOperand + "°";
|
||||
} else if (operator == '2') {
|
||||
return "cos" + secondOperand + "°";
|
||||
} else if (operator == '3') {
|
||||
return "tan" + secondOperand + "°";
|
||||
} else if (operator == '²') {
|
||||
return firstOperand + "" + operator;
|
||||
} else {
|
||||
if (random.nextBoolean()) {
|
||||
return firstOperand + " " + operator + " " + secondOperand;
|
||||
} else {
|
||||
return "(" + firstOperand + " " + operator + " " + secondOperand + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getRandomOperator(String operators) {
|
||||
return operators.charAt(random.nextInt(operators.length()));
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
// Main.java
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* 程序主入口类。
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
User user = new User("0", "0", "0");
|
||||
user.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
// Makeproblem.java
|
||||
/**
|
||||
* 数学题目生成器接口。
|
||||
*/
|
||||
public interface MathProblemGenerator {
|
||||
String generateSmartExpression();
|
||||
String buildExpression(int operatorCount, int complexityTarget);
|
||||
String generateSimpleExpression(int advancedOperationTarget);
|
||||
char getRandomOperator(String availableOperators);
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
// Middleproblem.java
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 初中数学题目生成器实现类。
|
||||
*/
|
||||
public class MiddleSchoolProblemGenerator implements MathProblemGenerator {
|
||||
private final Random random = new Random();
|
||||
private static int advancedOperationFlag = 1;
|
||||
private String userName = "default";
|
||||
private String timestamp = "default";
|
||||
private int problemNumber = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int index = 0; index < 15; index++) {
|
||||
advancedOperationFlag = 1;
|
||||
MiddleSchoolProblemGenerator generator = new MiddleSchoolProblemGenerator();
|
||||
System.out.println((index + 1) + ". " + generator.generateSmartExpression());
|
||||
}
|
||||
}
|
||||
|
||||
public void start(int problemCount, String userName) {
|
||||
this.userName = userName;
|
||||
TimeManager timeManager = new TimeManager();
|
||||
timestamp = timeManager.getCurrentTime();
|
||||
|
||||
for (int index = 0; index < problemCount; index++) {
|
||||
advancedOperationFlag = 1;
|
||||
System.out.println((index + 1) + ". " + generateSmartExpression());
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSmartExpression() {
|
||||
int operatorCount = random.nextInt(3) + 1;
|
||||
int advancedOperationTarget = random.nextInt(operatorCount) + 1;
|
||||
String result;
|
||||
|
||||
while (true) {
|
||||
boolean isDuplicate = false;
|
||||
result = buildExpression(operatorCount, advancedOperationTarget);
|
||||
|
||||
FileManager fileManager = new FileManager();
|
||||
fileManager.readUserFiles(userName);
|
||||
|
||||
for (String line : fileManager.getFileLines()) {
|
||||
String[] parts = line.split("\\.", 2);
|
||||
String expression = parts.length > 1 ? parts[1] : line;
|
||||
if (result.equals(expression)) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDuplicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fileManager.createUserFile(userName, timestamp);
|
||||
fileManager.writeToFile(userName, timestamp, problemNumber + "." + result);
|
||||
fileManager.writeToFile(userName, timestamp, " ");
|
||||
problemNumber++;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildExpression(int operatorCount, int advancedOperationTarget) {
|
||||
if (operatorCount == 1) {
|
||||
return generateSimpleExpression(advancedOperationTarget);
|
||||
}
|
||||
|
||||
int splitPoint = random.nextInt(operatorCount - 1) + 1;
|
||||
|
||||
String leftPart = (splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(splitPoint, advancedOperationTarget) + ")"
|
||||
: buildExpression(splitPoint, advancedOperationTarget);
|
||||
|
||||
String rightPart = (operatorCount - splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(operatorCount - splitPoint, advancedOperationTarget) + ")"
|
||||
: buildExpression(operatorCount - splitPoint, advancedOperationTarget);
|
||||
|
||||
char operator = getRandomOperator("+-*/");
|
||||
return leftPart + " " + operator + " " + rightPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSimpleExpression(int advancedOperationTarget) {
|
||||
int firstOperand = random.nextInt(100) + 1;
|
||||
int secondOperand = random.nextInt(100) + 1;
|
||||
char operator = getRandomOperator("+-*/√²");
|
||||
|
||||
if (advancedOperationFlag == advancedOperationTarget) {
|
||||
operator = getRandomOperator("√²");
|
||||
if (operator == '√') {
|
||||
advancedOperationFlag = 0;
|
||||
return operator + "" + secondOperand;
|
||||
} else if (operator == '²') {
|
||||
advancedOperationFlag = 0;
|
||||
return firstOperand + "" + operator;
|
||||
}
|
||||
} else {
|
||||
advancedOperationFlag++;
|
||||
}
|
||||
|
||||
if (random.nextInt(2) == 0) {
|
||||
return firstOperand + "";
|
||||
}
|
||||
|
||||
if (operator == '√') {
|
||||
return operator + "" + secondOperand;
|
||||
} else if (operator == '²') {
|
||||
return firstOperand + "" + operator;
|
||||
} else {
|
||||
if (random.nextBoolean()) {
|
||||
return firstOperand + " " + operator + " " + secondOperand;
|
||||
} else {
|
||||
return "(" + firstOperand + " " + operator + " " + secondOperand + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getRandomOperator(String operators) {
|
||||
return operators.charAt(random.nextInt(operators.length()));
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
// Primaryproblem.java
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 小学数学题目生成器实现类。
|
||||
*/
|
||||
public class PrimarySchoolProblemGenerator implements MathProblemGenerator {
|
||||
private static final Random random = new Random();
|
||||
private static int basicOperationCounter = 1;
|
||||
private static int expressionComplexityCounter = 1;
|
||||
private String userName = "default";
|
||||
private String timestamp = "default";
|
||||
private int problemNumber = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
PrimarySchoolProblemGenerator generator = new PrimarySchoolProblemGenerator();
|
||||
generator.userName = "张三1";
|
||||
TimeManager timeManager = new TimeManager();
|
||||
generator.timestamp = timeManager.getCurrentTime();
|
||||
|
||||
for (int index = 0; index < 15; index++) {
|
||||
basicOperationCounter = 1;
|
||||
expressionComplexityCounter = 1;
|
||||
System.out.println((index + 1) + ". " + generator.generateSmartExpression());
|
||||
generator.problemNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
public void start(int problemCount, String userName) {
|
||||
this.userName = userName;
|
||||
TimeManager timeManager = new TimeManager();
|
||||
timestamp = timeManager.getCurrentTime();
|
||||
|
||||
for (int index = 0; index < problemCount; index++) {
|
||||
basicOperationCounter = 1;
|
||||
expressionComplexityCounter = 1;
|
||||
System.out.println((index + 1) + ". " + generateSmartExpression());
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSmartExpression() {
|
||||
int operatorCount = random.nextInt(3) + 1;
|
||||
int basicOperationTarget = random.nextInt(operatorCount) + 1;
|
||||
String result;
|
||||
|
||||
while (true) {
|
||||
boolean isDuplicate = false;
|
||||
result = buildExpression(operatorCount, basicOperationTarget);
|
||||
|
||||
ExpressionJudge expressionJudge = new ExpressionJudge();
|
||||
if (expressionJudge.hasError(result)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FileManager fileManager = new FileManager();
|
||||
fileManager.readUserFiles(userName);
|
||||
|
||||
for (String line : fileManager.getFileLines()) {
|
||||
String[] parts = line.split("\\.", 2);
|
||||
String expression = parts.length > 1 ? parts[1] : line;
|
||||
if (result.equals(expression)) {
|
||||
isDuplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isDuplicate) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fileManager.createUserFile(userName, timestamp);
|
||||
fileManager.writeToFile(userName, timestamp, problemNumber + "." + result);
|
||||
fileManager.writeToFile(userName, timestamp, " ");
|
||||
problemNumber++;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildExpression(int operatorCount, int basicOperationTarget) {
|
||||
if (operatorCount == 1) {
|
||||
return generateSimpleExpression(basicOperationTarget);
|
||||
}
|
||||
|
||||
int splitPoint = random.nextInt(operatorCount - 1) + 1;
|
||||
|
||||
String leftPart = (splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(splitPoint, basicOperationTarget) + ")"
|
||||
: buildExpression(splitPoint, basicOperationTarget);
|
||||
|
||||
String rightPart = (operatorCount - splitPoint > 1 && random.nextBoolean())
|
||||
? "(" + buildExpression(operatorCount - splitPoint, basicOperationTarget) + ")"
|
||||
: buildExpression(operatorCount - splitPoint, basicOperationTarget);
|
||||
|
||||
char operator = getRandomOperator("+-*/");
|
||||
return leftPart + " " + operator + " " + rightPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateSimpleExpression(int basicOperationTarget) {
|
||||
int firstOperand = random.nextInt(100) + 1;
|
||||
int secondOperand = random.nextInt(100) + 1;
|
||||
char operator = getRandomOperator("+-*/");
|
||||
|
||||
if (expressionComplexityCounter == 3) {
|
||||
return firstOperand + "";
|
||||
}
|
||||
|
||||
if (basicOperationCounter == basicOperationTarget) {
|
||||
operator = getRandomOperator("+-*/");
|
||||
expressionComplexityCounter++;
|
||||
return firstOperand + " " + operator + " " + secondOperand;
|
||||
} else {
|
||||
basicOperationCounter++;
|
||||
}
|
||||
|
||||
if (random.nextInt(2) == 0) {
|
||||
return firstOperand + "";
|
||||
}
|
||||
|
||||
if (random.nextBoolean()) {
|
||||
expressionComplexityCounter++;
|
||||
return firstOperand + " " + operator + " " + secondOperand;
|
||||
} else {
|
||||
expressionComplexityCounter++;
|
||||
return "(" + firstOperand + " " + operator + " " + secondOperand + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getRandomOperator(String operators) {
|
||||
return operators.charAt(random.nextInt(operators.length()));
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// Timemanage.java
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 时间管理工具类。
|
||||
*/
|
||||
public class TimeManager {
|
||||
public static void main(String[] args) {
|
||||
TimeManager timeManager = new TimeManager();
|
||||
System.out.println(timeManager.getCurrentTime());
|
||||
}
|
||||
|
||||
public String getCurrentTime() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年-MM月-dd日-HH时-mm分-ss秒");
|
||||
return now.format(formatter);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue