为了实现这个需求,我们首先定义一个枚举类型Grade来表示不同年级:
public enum Grade {
GRADE_ONE, GRADE_TWO
}
接着,我们定义一个枚举类型QuestionType来表示不同的题目类型:
public enum QuestionType {
ADDITION_10_STEP_1, ADDITION_10_STEP_2, ADDITION_20_STEP_1, ADDITION_20_STEP_2,
SUBTRACTION_10_STEP_1, SUBTRACTION_10_STEP_2, SUBTRACTION_20_STEP_1, SUBTRACTION_20_STEP_2,
NO_CARRY_ADDITION_100, NO_BORROW_SUBTRACTION_100, CARRY_ADDITION_100, BORROW_SUBTRACTION_100,
COMBINED_100_ADD_SUB, MIXED
}
其中,ADDITION_10_STEP_1表示一年级10以内的加法,ADDITION_10_STEP_2表示一年级10以内的双步加法,ADDITION_20_STEP_1表示一年级10-20的加法,ADDITION_20_STEP_2表示一年级10-20的双步加法,SUBTRACTION_10_STEP_1表示一年级10以内的减法,SUBTRACTION_10_STEP_2表示一年级10以内的双步减法,SUBTRACTION_20_STEP_1表示一年级10-20的减法,SUBTRACTION_20_STEP_2表示一年级10-20的双步减法,NO_CARRY_ADDITION_100表示二年级不进位加法,NO_BORROW_SUBTRACTION_100表示二年级不退位减法,CARRY_ADDITION_100表示二年级进位加法,BORROW_SUBTRACTION_100表示二年级退位减法,COMBINED_100_ADD_SUB表示二年级加减混合,MIXED表示混合计算。
接着,我们定义一个QuestionGenerator类,用于根据年级和题目类型生成问题列表:
public class QuestionGenerator {
private static final Random random = new Random();
public static List<Question> generateQuestions(Grade grade, QuestionType type, int count) {
List<Question> questions = new ArrayList<>();
for (int i = 0; i < count; i++) {
if (type == QuestionType.ADDITION_10_STEP_1) {
int a = random.nextInt(10) + 1;
int b = random.nextInt(10 - a + 1);
String content = String.format("%d + %d = ", a, b);
int answer = a + b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.ADDITION_10_STEP_2) {
int a = random.nextInt(10) + 1;
int b = random.nextInt(10 - a + 1);
int c = random.nextInt(10);
String content = String.format("%d - %d - %d = ", a + b, a, c);
int answer = a + b - c;
questions.add(new Question(content, answer));
} else if (type == QuestionType.ADDITION_20_STEP_1) {
int a = random.nextInt(11) + 10;
int b = random.nextInt(20 - a + 1);
String content = String.format("%d + %d = ", a, b);
int answer = a + b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.ADDITION_20_STEP_2) {
int a = random.nextInt(11) + 10;
int b = random.nextInt(20 - a + 1);
int c = random.nextInt(10);
String content = String.format("%d - %d - %d = ", a + b, a, c);
int answer = a + b - c;
questions.add(new Question(content, answer));
} else if (type == QuestionType.SUBTRACTION_10_STEP_1) {
int a = random.nextInt(10) + 1;
int b = random.nextInt(a);
String content = String.format("%d - %d = ", a, b);
int answer = a - b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.SUBTRACTION_10_STEP_2) {
int a = random.nextInt(10) + 1;
int b = random.nextInt(a);
int c = random.nextInt(b + 1);
String content = String.format("%d - %d - %d = ", a, b, c);
int answer = a - b - c;
questions.add(new Question(content, answer));
} else if (type == QuestionType.ADDITION_20_STEP_1) {
int a = random.nextInt(11) + 10;
int b = random.nextInt(a - 10 + 1) + 10;
String content = String.format("%d - %d = ", a, b);
int answer = a - b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.SUBTRACTION_20_STEP_2) {
int a = random.nextInt(11) + 10;
int b = random.nextInt(a - 10 + 1) + 10;
int c = random.nextInt(b - 10 + 1);
String content = String.format("%d - %d - %d = ", a, b, c);
int answer = a - b - c;
questions.add(new Question(content, answer));
} else if (type == QuestionType.NO_CARRY_ADDITION_100) {
int a = random.nextInt(90) + 10;
int b = random.nextInt(90) + 10;
while (b % 10 + a % 10 >= 10) {
b = random.nextInt(90) + 10;
}
String content = String.format("%d + %d = ", a, b);
int answer = a + b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.NO_BORROW_SUBTRACTION_100) {
int a = random.nextInt(90) + 10;
int b = random.nextInt(a - 10 + 1) + 10;
while (b % 10 > a % 10) {
b = random.nextInt(a - 10 + 1) + 10;
}
String content = String.format("%d - %d = ", a, b);
int answer = a - b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.CARRY_ADDITION_100) {
int a = random.nextInt(90) + 10;
int b = random.nextInt(90) + 10;
while (b % 10 + a % 10 < 10) {
b = random.nextInt(90) + 10;
}
String content = String.format("%d + %d = ", a, b);
int answer = a + b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.BORROW_SUBTRACTION_100) {
int a = random.nextInt(90) + 10;
int b = random.nextInt(a - 10 + 1) + 10;
while (b % 10 <= a % 10) {
b = random.nextInt(a - 10 + 1) + 10;
}
String content = String.format("%d - %d = ", a, b);
int answer = a - b;
questions.add(new Question(content, answer));
} else if (type == QuestionType.COMBINED_100_ADD_SUB) {
int a = random.nextInt(90) + 10;
int b = random.nextInt(90) + 10;
int c = random.nextInt(2);
if (c ==