Compare commits

...

40 Commits

Author SHA1 Message Date
hnu202326010302 1b195fb517 Merge pull request '1' (#2) from develop into main
3 days ago
hnu202326010302 1b6facee75 Delete 'doc/新建 文本文档.txt'
4 days ago
hnu202326010302 f92b87fd21 ADD file via upload
4 days ago
hnu202326010302 d628c0778e ADD file via upload
4 days ago
hnu202326010302 6bf3a92a98 ADD file via upload
4 days ago
hnu202326010302 27afde4001 ADD file via upload
4 days ago
hnu202326010302 29e1d31de7 ADD file via upload
4 days ago
hnu202326010302 06383dd7fa ADD file via upload
4 days ago
hnu202326010302 f47190ba33 ADD file via upload
4 days ago
hnu202326010302 b6d5009f4d ADD file via upload
4 days ago
hnu202326010302 3e844b36df ADD file via upload
4 days ago
hnu202326010302 8f6c53ba0f ADD file via upload
4 days ago
hnu202326010302 d509b020e0 ADD file via upload
4 days ago
hnu202326010302 bf83eee086 Delete 'src/problem.java'
4 days ago
hnu202326010302 786047512d Delete 'src/filemanage.java'
4 days ago
hnu202326010302 b645ab6ea3 Delete 'src/User.java'
4 days ago
hnu202326010302 e7abfe6c72 Delete 'src/Timemanage.java'
4 days ago
hnu202326010302 4ab0b123e8 Delete 'src/Primaryproblem.java'
4 days ago
hnu202326010302 9f9468503a Delete 'src/Middleproblem.java'
4 days ago
hnu202326010302 2ecc7b61ed Delete 'src/Highproblem.java'
4 days ago
hnu202326010302 2c3fe6fd20 Delete 'src/Expressionjurge.java'
4 days ago
hnu202326010302 11a0dc8ca1 Delete 'src/Makeproblem.java'
4 days ago
hnu202326010302 7f81627251 ADD file via upload
4 days ago
hnu202326010302 9336c64b08 Delete 'src/Main.java'
4 days ago
hnu202326010302 2e7f6938b0 ADD file via upload
6 days ago
hnu202326010302 33327f1696 Delete 'doc/新建 文本文档.txt'
6 days ago
hnu202326010302 0597821cb5 ADD file via upload
6 days ago
hnu202326010302 99c689c3ce ADD file via upload
6 days ago
hnu202326010302 68fadea367 ADD file via upload
6 days ago
hnu202326010302 bbd99b7e2b ADD file via upload
6 days ago
hnu202326010302 a4dc18d25e ADD file via upload
6 days ago
hnu202326010302 de25bcab06 ADD file via upload
6 days ago
hnu202326010302 16e6e8d180 ADD file via upload
6 days ago
hnu202326010302 bc0b7b7747 ADD file via upload
6 days ago
hnu202326010302 560d383916 ADD file via upload
6 days ago
hnu202326010302 fcc2027f48 ADD file via upload
6 days ago
hnu202326010302 2b6717e350 ADD file via upload
6 days ago
hnu202326010302 b27ad4d96e Delete 'README.md'
6 days ago
hnu202326010302 5390a50932 Delete 'Expressionjurge.java'
6 days ago
hnu202326010302 ec306b342a ADD file via upload
6 days ago

@ -0,0 +1,234 @@
# 中小学数学卷子自动生成程序 - Java版本说明文档
## 项目概述
这是一个基于Java开发的中小学数学卷子自动生成程序支持小学、初中和高中三个年级的数学题目生成具有用户登录验证、题目生成、年级切换和试卷保存等功能。
## 功能特性
### 1. 用户登录验证
- 支持小学、初中和高中各三个预设账号
- 用户名和密码用空格隔开输入
- 登录成功显示当前选择的出题年级
- 登录失败提示重新输入
### 2. 题目生成
- **题目数量**10-30题或输入-1退出登录
- **操作数数量**1-5个
- **操作数范围**1-100
- **题目去重**:同一老师的题目不会与历史题目重复
### 3. 年级切换
- 支持在登录状态下切换出题年级
- 输入"切换为 XX"XX为小学、初中、高中
- 输入错误时提示重新输入
### 4. 试卷保存
- 按"年-月-日-时-分-秒.txt"格式命名
- 每个账号独立文件夹
- 题目有序号,每题间空一行
## 年级难度要求
### 小学
- 四则运算,结果非负
### 初中
- 包含平方、开根号运算
- 题目中至少有一个平方或开根号运算符
### 高中
- 包含三角函数sin, cos, tan
- 题目中至少有一个三角函数
## 使用流程
### 登录界面
```
== 中小学数学卷子自动生成程序 ==
欢迎你 张三1 小学
输入1开始出题
输入2切换出题年级
输入-1退出登录返回开始界面
```
### 出题流程
1. 输入1开始出题
2. 输入题目数量10-30
3. 系统生成对应年级难度的题目
4. 题目显示并自动保存
### 切换年级
例如,切换为初中
```
2
请输入想要切换的出题年级,输入-1返回操作界面
初中
已成功修改出题年级为初中,输入-1返回操作界面
```
### 登录过程
```
请输入用户名和密码(用空格分隔):
张三1 123
登录成功!当前选择为小学出题
== 中小学数学卷子自动生成程序 ==
欢迎你 张三1 小学
输入1开始出题
输入2切换出题年级
输入-1退出登录返回开始界面
```
### 题目生成示例
```
输入1开始出题
准备生成小学数学题目,请输入生成题目数量(输入-1将退出当前用户
10
正在为小学出题请在10-30的范围内输入出题数目
1. 92 + 96 - (58 / 55 * 62)
2. (24 * 13) * 34 + 15
3. 68 - 55 - 57 / 85 / 71
...
已出题完成,输入-1返回操作界面
```
### 年级切换
```
输入2切换出题年级
请输入想要切换的出题年级(小学、初中、高中):
初中
已成功修改出题年级为初中
```
## 文件保存格式
### 目录结构
```
User-problem/
├── 张三1/
│ ├── 2025-09-29-22-30-45.txt
│ └── 2025-09-29-22-35-20.txt
├── 李四2/
│ └── 2025-09-29-22-40-15.txt
```
### 文件内容格式
```
1. 92 + 96 - (58 / 55 * 62)
2. (24 * 13) * 34 + 15
3. 68 - 55 - 57 / 85 / 71
...
```
## 系统架构
### 核心类说明
#### 1. Main.java
- **功能**: 程序主入口
- **职责**: 启动用户登录流程
#### 2. User.java
- **功能**: 用户管理类
- **职责**:
- 处理用户登录验证
- 管理用户账户信息(用户名、密码、年级)
- 初始化预设用户数据
#### 3. ProblemManager.java
- **功能**: 问题管理类
- **职责**:
- 显示主界面
- 处理用户交互
- 协调题目生成流程
- 提供年级切换功能
#### 4. 题目生成器接口和实现类
**MathProblemGenerator.java** (接口)
- 定义题目生成器的统一接口
**PrimarySchoolProblemGenerator.java** (小学题目生成器)
- 生成包含基本四则运算的题目
**MiddleSchoolProblemGenerator.java** (初中题目生成器)
- 在小学基础上增加平方(²)和开方(√)运算
**HighSchoolProblemGenerator.java** (高中题目生成器)
- 在初中基础上增加三角函数(sin, cos, tan)运算
#### 5. 工具类
**ExpressionJudge.java**
- **功能**: 表达式验证工具
- **职责**: 检测数学表达式中的语法错误和语义错误
**FileManager.java**
- **功能**: 文件管理工具
- **职责**: 处理用户题目文件的读写操作
**TimeManager.java**
- **功能**: 时间管理工具
- **职责**: 提供时间戳生成功能
## 已知问题:除零错误
### 问题描述
在生成初中高中题目时,存在**生成除零式子**的风险。
在生成初中高中题目时生成有5个操作数的式子概率比较低可能一次出题不会有要多次出题才会出现。

@ -0,0 +1,18 @@
# 中小学数学卷子自动生成程序 - 运行环境说明
## 系统要求
### 操作系统
- **推荐系统**: Linux (Ubuntu 20.04+, CentOS 7+, 或其他主流Linux发行版)
- **已验证环境**: Linux系统
- **兼容性**: 理论上支持所有Linux发行版
### Java环境
- **JDK版本**: Java 17
## 运行说明
- 进入release文件运行release.jar文件
- release文件内在Linux终端命令行中运行java -jar release.jar即可进入程序运行。

@ -0,0 +1,100 @@
// Expressionjurge.java
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.Map;
import java.util.HashMap;
/**
*
*/
public class ExpressionJudge {
public boolean hasError(String expression) {
try {
String cleanExpression = expression.replaceAll("\\s+", "");
List<Object> reversePolishNotation = infixToReversePolishNotation(cleanExpression);
return evaluateReversePolishNotation(reversePolishNotation);
} catch (Exception exception) {
return true; // 任何异常都视为有错误
}
}
private static List<Object> infixToReversePolishNotation(String expression) {
List<Object> output = new ArrayList<>();
Stack<Character> operators = new Stack<>();
StringBuilder number = new StringBuilder();
Map<Character, Integer> precedence = Map.of('+', 1, '-', 1, '*', 2, '/', 2);
for (int index = 0; index < expression.length(); index++) {
char character = expression.charAt(index);
if (Character.isDigit(character) || character == '.') {
number.append(character);
} else {
if (number.length() > 0) {
output.add(Double.parseDouble(number.toString()));
number = new StringBuilder();
}
if (character == '(') {
operators.push(character);
} else if (character == ')') {
while (!operators.isEmpty() && operators.peek() != '(') {
output.add(operators.pop());
}
if (!operators.isEmpty()) operators.pop();
} else if (isOperator(character)) {
while (!operators.isEmpty() && operators.peek() != '(' &&
precedence.getOrDefault(operators.peek(), 0) >= precedence.get(character)) {
output.add(operators.pop());
}
operators.push(character);
}
}
}
if (number.length() > 0) {
output.add(Double.parseDouble(number.toString()));
}
while (!operators.isEmpty()) {
output.add(operators.pop());
}
return output;
}
private static boolean evaluateReversePolishNotation(List<Object> reversePolishNotation) {
Stack<Double> stack = new Stack<>();
for (Object token : reversePolishNotation) {
if (token instanceof Double) {
stack.push((Double) token);
} else {
char operator = (Character) token;
if (stack.size() < 2) return true; // 表达式错误
double secondOperand = stack.pop();
double firstOperand = stack.pop();
double result;
switch (operator) {
case '+': result = firstOperand + secondOperand; break;
case '-':
result = firstOperand - secondOperand;
if (result < 0) return true; // 发现负数
break;
case '*': result = firstOperand * secondOperand; break;
case '/':
if (secondOperand == 0) return true; // 发现除零
result = firstOperand / secondOperand;
if (result < 0) return true; // 发现负数
break;
default: return true; // 未知运算符
}
stack.push(result);
}
}
return stack.size() != 1; // 如果栈中不是恰好一个元素,说明表达式错误
}
private static boolean isOperator(char character) {
return character == '+' || character == '-' || character == '*' || character == '/';
}
}

@ -0,0 +1,109 @@
// filemanage.java
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
*
*/
public class FileManager {
private final List<String> fileLines = new ArrayList<>();
public static void main(String[] args) {
FileManager fileManager = new FileManager();
fileManager.createUserFile("张三1", "123");
fileManager.readUserFiles("张三1");
for (String line : fileManager.fileLines) {
System.out.println(line);
}
fileManager.writeToFile("张三1", "123", "1");
}
/**
*
*/
public static List<String> getFileNames(String userName) throws IOException {
Path directoryPath = Path.of("User-problem");
Path userDirectoryPath = directoryPath.resolve(userName);
try (var files = Files.list(userDirectoryPath)) {
return files.filter(Files::isRegularFile)
.map(path -> path.getFileName().toString())
.collect(Collectors.toList());
}
}
/**
*
*/
public void readUserFiles(String userName) {
Path directoryPath = Path.of("User-problem");
Path userDirectoryPath = directoryPath.resolve(userName);
try {
List<String> fileNames = getFileNames(userName);
for (String fileName : fileNames) {
Path filePath = userDirectoryPath.resolve(fileName);
try {
List<String> lines = Files.readAllLines(filePath);
fileLines.addAll(lines);
} catch (IOException exception) {
exception.printStackTrace();
}
}
} catch (IOException exception) {
//exception.printStackTrace();
//没读取到文件时无需处理,稍后新建文件
}
}
/**
*
*/
public void writeToFile(String userName, String timestamp, String content) {
List<String> linesToWrite = new ArrayList<>();
linesToWrite.add(content);
String fileName = timestamp + ".txt";
Path directoryPath = Path.of("User-problem");
Path userDirectoryPath = directoryPath.resolve(userName);
Path filePath = userDirectoryPath.resolve(fileName);
try {
Files.write(filePath, linesToWrite, StandardOpenOption.APPEND);
} catch (IOException exception) {
exception.printStackTrace();
}
}
/**
*
*/
public void createUserFile(String userName, String timestamp) {
String fileName = timestamp + ".txt";
try {
Path directoryPath = Paths.get("User-problem");
if (!Files.exists(directoryPath)) {
Files.createDirectories(directoryPath);
}
Path userDirectoryPath = directoryPath.resolve(userName);
if (!Files.exists(userDirectoryPath)) {
Files.createDirectories(userDirectoryPath);
}
Path filePath = userDirectoryPath.resolve(fileName);
Files.createFile(filePath);
} catch (FileAlreadyExistsException exception) {
// 文件已存在,无需操作
} catch (IOException exception) {
exception.printStackTrace();
}
}
public List<String> getFileLines() {
return fileLines;
}
}

@ -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,141 @@
// problem.java
import java.util.Scanner;
import java.io.IOException;
/**
*
*/
public class ProblemManager {
private String currentLevel;
private String currentUserName;
public void display() {
try {
new ProcessBuilder("clear").inheritIO().start().waitFor();
} catch (IOException | InterruptedException exception) {
// 清屏失败,继续执行
}
System.out.println("=== 中小学数学卷子自动生成程序 ===");
}
public void start(User user) {
currentLevel = user.getLevel();
currentUserName = user.getUsername();
while (true) {
display();
System.out.println("欢迎你 " + user.getUsername() + " " + currentLevel);
System.out.println("输入1开始出题");
System.out.println("输入2切换出题年级");
System.out.println("输入-1退出登录返回开始界面");
Scanner scanner = new Scanner(System.in);
int choice = 0;
while (true) {
String input = scanner.next();
try {
choice = Integer.parseInt(input);
} catch (NumberFormatException exception) {
choice = 0;
}
if (choice == 1 || choice == 2 || choice == -1) {
break;
} else {
System.out.println("请输入正确的操作");
}
}
if (choice == 1) {
if (generateProblems() == 0) {
continue;
}
}
if (choice == 2) {
if (switchLevel() == 0) {
continue;
}
}
if (choice == -1) {
break;
}
}
}
public int generateProblems() {
System.out.println("正在为" + currentLevel + "出题");
System.out.println("请在10-30的范围内输入出题数目输入-1返回操作界面");
Scanner scanner = new Scanner(System.in);
int problemCount = 0;
while (true) {
String input = scanner.next();
try {
problemCount = Integer.parseInt(input);
} catch (NumberFormatException exception) {
problemCount = 0;
}
if (problemCount == -1) {
break;
}
if (problemCount >= 10 && problemCount <= 30) {
break;
} else {
System.out.println("请输入10-30范围的出题数");
}
}
if (problemCount == -1) {
return 0;
}
if (currentLevel.equals("小学")) {
PrimarySchoolProblemGenerator primaryGenerator = new PrimarySchoolProblemGenerator();
primaryGenerator.start(problemCount, currentUserName);
} else if (currentLevel.equals("初中")) {
MiddleSchoolProblemGenerator middleGenerator = new MiddleSchoolProblemGenerator();
middleGenerator.start(problemCount, currentUserName);
} else if (currentLevel.equals("高中")) {
HighSchoolProblemGenerator highGenerator = new HighSchoolProblemGenerator();
highGenerator.start(problemCount, currentUserName);
}
System.out.println("已出题完成,输入-1返回操作界面");
while (!scanner.next().equals("-1")) {
continue;
}
return 0;
}
public int switchLevel() {
System.out.println("请输入想要切换的出题年级,输入-1返回操作界面");
Scanner scanner = new Scanner(System.in);
String newLevel;
while (true) {
newLevel = scanner.next();
if (newLevel.equals("-1")) {
break;
}
if (newLevel.equals("初中") || newLevel.equals("小学") || newLevel.equals("高中")) {
break;
} else {
System.out.println("请输入小学、初中和高中三个选项中的一个");
}
}
if (newLevel.equals("-1")) {
return 0;
}
currentLevel = newLevel;
System.out.println("已成功修改出题年级为" + currentLevel + ",输入-1返回操作界面");
while (!scanner.next().equals("-1")) {
continue;
}
return 0;
}
}

@ -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);
}
}

@ -0,0 +1,87 @@
// User.java
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
/**
*
*/
public class User {
private String username;
private String password;
private String level;
private final ArrayList<User> userList = new ArrayList<>();
private int loginState = 1;
public boolean login() {
if (loginState == 1) {
try {
new ProcessBuilder("clear").inheritIO().start().waitFor();
} catch (IOException | InterruptedException exception) {
// 清屏失败,继续执行
}
System.out.println("=== 中小学数学卷子自动生成程序 ===");
System.out.println("请输入账户名称,密码:");
}
Scanner scanner = new Scanner(System.in);
String inputUsername = scanner.next();
String inputPassword = scanner.next();
for (User user : userList) {
if (inputUsername.equals(user.getUsername()) && inputPassword.equals(user.getPassword())) {
this.username = inputUsername;
this.password = inputPassword;
this.level = user.getLevel();
loginState = 1;
return true;
}
}
System.out.println("请输入正确的用户名、密码");
loginState = 0;
return true;
}
public void start() {
initializeUsers();
while (login()) {
if (loginState == 0) {
continue;
} else if (loginState == 1) {
ProblemManager problemManager = new ProblemManager();
problemManager.start(this);
}
}
}
public User(String username, String password, String level) {
this.username = username;
this.password = password;
this.level = level;
}
private void initializeUsers() {
userList.add(new User("张三1", "123", "小学"));
userList.add(new User("张三2", "123", "小学"));
userList.add(new User("张三3", "123", "小学"));
userList.add(new User("李四1", "123", "初中"));
userList.add(new User("李四2", "123", "初中"));
userList.add(new User("李四3", "123", "初中"));
userList.add(new User("王五1", "123", "高中"));
userList.add(new User("王五2", "123", "高中"));
userList.add(new User("王五3", "123", "高中"));
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getLevel() {
return level;
}
}
Loading…
Cancel
Save