合并至main分支 #1

Merged
hnu202326010223 merged 9 commits from develop into main 3 months ago

39
.gitignore vendored

@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="MathGenerator1:jar">
<output-path>$PROJECT_DIR$/out/artifacts/MathGenerator1_jar</output-path>
<root id="archive" name="MathGenerator1.jar">
<element id="module-output" name="MathGenerator1" />
</root>
</artifact>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -1,2 +1,298 @@
# MathGenerator
中小学数学卷子自动生成程序
项目概述
中小学数学卷子自动生成程序是一个基于 Java 开发的命令行应用程序,旨在帮助小学、初中和高中数学老师快速生成符合教学要求的数学题目。程序支持不同难度级别的题目生成、用户认证、题目查重和文件保存等功能。
核心功能
🔐 用户认证系统
预设账户:系统内置小学、初中、高中各三个教师账户
登录验证:通过用户名和密码进行身份验证
权限分级:根据账户类型自动确定题目难度级别
📚 题目生成引擎
小学题目
运算符:加(+)、减(-)、乘(\*)、除(/)
特殊要求:可能包含括号
操作数2-5个操作数取值范围1-100
初中题目
运算符:包含平方(²)、开根号(√)等高级运算符
特殊要求:至少包含一个平方或开根号运算符,且必须通过四则运算连接其他操作数
操作数3-5个操作数取值范围1-100
高中题目
运算符:包含三角函数(sin、cos、tan)
特殊要求:至少包含一个三角函数和一个平方/开根号运算符
操作数2-5个操作数取值范围1-100
🔄 交互功能
难度切换:登录后可通过命令切换题目难度
题目数量控制支持生成10-30道题目
重复检测:避免生成与历史题目重复的内容
灵活退出:支持退出当前用户重新登录
💾 文件管理
按用户分文件夹:每个用户的题目单独存放
时间戳命名:文件格式为"年-月-日-时-分-秒.txt"
规范格式:每道题目有序号,题目间空一行
技术架构
项目结构
text
MathGenerator/
└── src/
&nbsp; └── test/
&nbsp; └── java/
&nbsp; ├── main/
&nbsp; │ └── Main.java # 主程序入口
&nbsp; ├── entity/
&nbsp; │ ├── User.java # 用户实体类
&nbsp; │ └── Question.java # 题目实体类
&nbsp; ├── service/
&nbsp; │ ├── UserService.java # 用户认证服务
&nbsp; │ ├── QuestionService.java # 题目生成服务
&nbsp; │ ├── FileService.java # 文件操作服务
&nbsp; │ └── ValidationService.java # 输入验证服务
&nbsp; ├── factory/
&nbsp; │ ├── QuestionFactory.java # 题目生成器工厂
&nbsp; │ └── QuestionGenerator.java # 题目生成器接口
&nbsp; └── generator/
&nbsp; ├── PrimaryQuestionGenerator.java # 小学题目生成器
&nbsp; ├── JuniorQuestionGenerator.java # 初中题目生成器
&nbsp; └── SeniorQuestionGenerator.java # 高中题目生成器
设计模式
工厂模式:通过 QuestionFactory 创建不同难度的题目生成器
策略模式QuestionGenerator 接口支持多难度题目生成策略
分层架构:清晰的 entity-service-factory 分层结构
使用指南
启动程序
bash
mvn clean package
java -jar target/math-test-generator.jar
操作流程
登录系统
text
请输入用户名和密码(用空格隔开): 张三1 123
当前选择为小学出题
生成题目
text
准备生成小学数学题目,请输入生成题目数量(输入-1将退出当前用户重新登录: 15
题目已生成并保存到: exams/张三1/2025-01-20-14-30-25.txt
切换难度
text
切换为初中
准备生成初中数学题目,请输入生成题目数量
退出登录
text
输入-1将退出当前用户重新登录
预设账户
类型 用户名 密码
小学 张三1, 张三2, 张三3 123
初中 李四1, 李四2, 李四3 123
高中 王五1, 王五2, 王五3 123
代码规范
项目严格遵循 Google Java 编码规范:
使用 2 空格缩进
完整的 Javadoc 注释
清晰的包和类结构
方法长度控制在 40 行以内
有意义的命名约定
输出示例
生成的题目文件格式:
text
1\. 25 + 47 - 13
2\. (18 \* 3) / 6 + 29
3\. 45 - 17 + 32 \* 2
...
扩展性
程序具有良好的扩展性,可以轻松:
添加新的题目难度级别
支持更多的数学运算符
集成数据库存储
添加图形用户界面
支持自定义题目模板
该项目专为中小学数学教育设计,帮助教师提高出题效率,确保题目质量一致性。

@ -0,0 +1,20 @@
1. 39 - 97 * 72
2. 79 - 23
3. 93 - 22
4. 83 + (9 - 61 / 41 + 100)
5. 82 * 100
6. (7 * 12 - 31)
7. 3 + 84 + 89 - 2 + 7
8. 70 - 72
9. 67 - 27 - 98 - (45 / 17)
10. 96 / 55 - 17 * 84

@ -0,0 +1,22 @@
1. 24 / 82 - 98 * 51
2. 33 * 57 / 8
3. 66 / 41 * 71 + (96 * 8)
4. 39 + 53 - (58 - 23)
5. 33 + 25 * 26 + 74 / 30
6. 57 - 86
7. 84 / 80 - 90 + (92 + 73)
8. 39 + 24 - 36
9. 98 + (74 + 39)
10. 40 / 75 * 4 - 22
11. 30 / 67

@ -0,0 +1,24 @@
1. 1 + 35 - 4
2. 49 + 93
3. 58 / 69 * 47
4. 20 - 80 + 35 + 80 * 91
5. 57 * 95 / 61 * 12
6. 12 + 94
7. 53 + 56 / 9
8. 47 + 38
9. 86 + 43 / 54 - 16
10. 84 / 93 * (53 / 82)
11. 43 * 94
12. 87 / 24 / 41 + 25 + 4

@ -0,0 +1,26 @@
1. 32 - 80 / 21
2. 57 / 55 / 39
3. 18 / 45 + 77
4. 48 + 99 / 7 + 34 * 93
5. (31 - 5 + 40)
6. 12 + 3 + 30
7. 26 / 100
8. 96 * 35 / (50 / 43)
9. 30 - 88 + 7 * 41 + 16
10. 92 * (100 / 13 - 9 + 76)
11. (33 / 11 * 1 + 77)
12. 89 - 95
13. 37 / 75 / 40 / 16

@ -0,0 +1,28 @@
1. 100 * 1 / 62
2. 35 * (96 / 52)
3. 30 + 88 + 43 * 27
4. 37 - (5 / 4 *) 68
5. (6 / 41 -) 8
6. 77 - 61 / 21 * 33
7. (24 * 12 * 58)
8. 91 / 93 / 31 - 26 * 15
9. 37 + 88 * 76 * 4
10. 54 - 9
11. 98 / 34
12. 94 + 94 * 62
13. 77 - 95 / 63
14. (61 / 15 * 33 + 82 + 99)

@ -0,0 +1,30 @@
1. 22 * 26 - 57 - 54 * 56
2. (89 - 32 /) 37
3. (52 / 90 - 81 /) 13
4. 29 - 63 - 18
5. 96 - 31 - 16 + 46 * 58
6. 5 - 41
7. 16 / 25 / 10
8. 58 - 3 / 50
9. 30 * 71 - 54 + 4 - 25
10. 28 / 51 + 6
11. 42 + 51
12. 84 / 12 * 89
13. 15 - 22
14. 92 + 55
15. 66 * 55 + 64 * 50

@ -0,0 +1,32 @@
1. 45 + 82 / 48 * 46 * 11
2. 82 * 11 + 96 / 78 + 72
3. 98 + (12 - 79)
4. 20 + 6 - 36 - 85
5. 76 - 88 * 30 * 4 - 27
6. 3 / 59 + 61 - 88 / 75
7. 99 + 39 + 66 - 57 / 17
8. 55 * (39 * 19 * 12)
9. 3 - 65 - 36 / 17 - 10
10. 89 * 36 / 26 * 52
11. 89 * 34
12. 13 / 45 - 49
13. 98 * 56 + 5
14. 74 * 45 * 2 - 2 - 10
15. 40 / 67 / 17 - 27 * 36
16. 3 * (73 + 88)

@ -0,0 +1,34 @@
1. 23 + 1
2. 63 + 81 / 61 * 2
3. 11 - 47 - 69 * 22
4. 87 / 30 * 60 + 6
5. 75 * 79 / 13 - 86
6. 29 * 63
7. 57 + 100 * 50 * 95 * 99
8. 39 - 97
9. 47 - 46 * (80 + 90 /) 7
10. (4 * 56 * 46)
11. 82 + 46 / 99 * 49
12. 1 + 97 * 55 / (17 * 77)
13. 61 / 61
14. 60 / (55 / 76)
15. 4 + 46 - 81
16. 1 + (27 - 55)
17. 93 / (75 + 33 - 53)

@ -0,0 +1,36 @@
1. 49 + 80 - 27 - 8
2. 73 * 63 / 44 + 23
3. (39 + 21 - 33 - 56 +) 60
4. 4 * 8 + 93 + 19 - 51
5. (35 + 76 / 23)
6. 48 - 6
7. 92 / 40 * 96
8. 11 + 18 / (51 + 97)
9. 47 * 95 - 34 - 88
10. (13 + 45 * 88)
11. 9 + 4 / 37 * 10 * 47
12. 60 - 12 / (25 / 100 *) 92
13. 72 * 27 + 90
14. 70 * 47 + 3
15. 57 + 6 - 14 / 7 * 30
16. 14 * 3 + 99 - 30 + 46
17. 74 / 58 / 58 * 76 + 47
18. 59 * 87

@ -0,0 +1,38 @@
1. (16 * 37 - 4)
2. 53 - 25
3. 20 + (86 / 41 * 48 * 50)
4. 78 * 55 * 98 - 91
5. 96 * 7 + (39 * 95)
6. 41 * 29 - 4 - 18 - 91
7. 75 / 89 + 53
8. 78 * 77
9. 5 * 57 * (51 + 25 /) 50
10. 67 - 87 - (83 / 21)
11. 33 / 38 / 86 - 3
12. 36 / 88 * 88 - 43 - 93
13. 60 * 26 - 27 - 38 - 3
14. 35 + 36
15. 85 - 47 - 4 / 28 - 44
16. (7 * 81 + 40)
17. 44 + (82 + 29 +) 50
18. 82 * (51 / 64)
19. 24 - 94 + 6

@ -0,0 +1,20 @@
1. (59)² / (45)² + 30 / 13
2. 34 * √(6) * √(55)
3. 70 - 75 * √(40) + 97
4. √(71) + (50)² * 29
5. 11 / √(13) - 10 - 74 - √(64)
6. √(84) + √(64) / (56)²
7. (26)² - (87)² * (10)²
8. 80 / (87)² / 12
9. (28)² + 37 + 46 + 26 / 16
10. 7 / 81 / 55 + √(55)

@ -0,0 +1,22 @@
1. √(24) / 5 * 94 * 70 * √(70)
2. 59 / 70 / (10)² / √(84)
3. √(52) - 88 * √(74)
4. (3)² - 86 + √(29) * (99)² + 40
5. 25 * (25)² + (46)² * 67
6. 87 + 17 * √(59) / (30)²
7. (18)² / 76 + 77 * 39 - (33)²
8. √(94) + 80 - 54 + √(52) * 51
9. (63)² - 44 - √(88) * (6)²
10. 39 - √(26) / √(35) - (55)² - 92
11. (100)² - 16 * 18 / (45)²

@ -0,0 +1,24 @@
1. 36 * (18)² * 69 * √(8)
2. (57)² + 39 * (35)² / (55)²
3. √(27) + (9)² * (37)²
4. 30 - 27 / (17)² * √(93) / (73)²
5. (60)² + 2 - 75
6. 11 * (47)² - (96)² * 17 * (62)²
7. 12 * √(56) + 88 - (100)² * 60
8. √(56) / 26 * 47 / √(67)
9. (49)² - √(64) * √(37) - (33)²
10. (53)² / 28 - 59 + 43 + √(98)
11. (63)² * 72 * √(3) * 50
12. (69)² - 65 * √(8) * √(7)

@ -0,0 +1,26 @@
1. (11)² - 53 / (57)²
2. 73 / √(71) + √(95) / 93 - 78
3. (10)² / √(3) - (64)² * (70)² + 69
4. 64 * 32 / (59)² - 59
5. √(65) - √(38) - √(91) - (91)² / √(31)
6. (94)² + (35)² / (15)²
7. 53 - √(100) + √(83)
8. (65)² - √(2) - (26)² - 60 + (73)²
9. √(51) - 31 / 79 * √(84)
10. 46 * 55 + √(16) - (19)²
11. √(7) * 61 + √(79) * √(51)
12. 16 - √(18) - √(95)
13. √(34) - 85 / √(7) - (33)²

@ -0,0 +1,28 @@
1. (6)² * √(60) + (97)²
2. (29)² + (47)² / 97
3. 56 * 84 * 46 / √(2)
4. 98 * √(64) - √(90)
5. (97)² / 95 / √(50) * 71
6. (98)² - (1)² * (68)² * 24
7. √(4) * (72)² * 100 * √(1) * (46)²
8. 9 - (1)² - 57 - (89)²
9. √(1) - (40)² + 18 - 38
10. 76 * 47 - (92)² + 80 / (77)²
11. 99 + √(65) + 8 - 86
12. 5 * (20)² / √(24) + 8
13. (14)² / √(30) * 47 - 79 + 32
14. √(88) + √(22) / (30)² - (90)²

@ -0,0 +1,30 @@
1. 37 * (21)² - 11
2. 99 / 95 + 17 + 91 - √(41)
3. (45)² - √(94) - (23)² * √(68) - (46)²
4. √(93) / 39 + (17)² / (89)² / (78)²
5. (8)² - (19)² * 15 * 67
6. √(95) - √(94) - 14 * √(98) * √(74)
7. (49)² / 34 + √(63) / √(29) - 90
8. 80 + √(1) * √(98) + 33 * 62
9. 8 + (13)² / 15
10. √(94) / (21)² - 43 / 91 + (41)²
11. √(60) * √(66) - 27
12. 9 * 98 * (91)² * √(72)
13. (75)² * √(92) / (97)² / (58)² - 16
14. √(65) / √(28) - 78 - 40 * (96)²
15. 28 / √(22) / (26)² + (72)² - √(26)

@ -0,0 +1,32 @@
1. 16 / (33)² - (71)²
2. 4 - √(23) - (52)² / 90 + (82)²
3. (48)² * (14)² + 12
4. √(16) - √(97) + 27
5. (92)² / √(22) / 22 * (68)² + (19)²
6. √(6) - 13 - √(67)
7. (16)² / 21 * √(16) - (40)² + (52)²
8. √(83) + √(43) / 71 * √(99) * 41
9. (3)² + (13)² - (1)²
10. √(61) * √(98) - √(72) * √(14) / √(55)
11. √(22) - √(28) + 59 * 65
12. 94 * 13 / (94)² * √(61) + 98
13. 14 - √(1) + 34 * 37
14. 29 - √(21) * 100 + 20
15. √(43) * 15 + √(48) + (92)² + 30
16. (100)² + (53)² / 88 + √(70)

@ -0,0 +1,34 @@
1. 12 / (39)² / 43 + 27 - (74)²
2. √(54) * (70)² + √(71)
3. 62 / (50)² / 19
4. √(69) / √(91) * 30 + 89
5. √(54) - 16 - (31)² * 31
6. (47)² - 69 / (35)²
7. √(27) / (55)² - √(1) - √(74) - 7
8. √(8) * 45 * 70 + (48)²
9. √(62) / √(74) / 17 - 89 + 26
10. 51 - √(27) - 51 / (2)² - 36
11. 61 - (52)² + √(9)
12. √(84) / √(75) + 89 * (58)²
13. √(27) - √(97) * 26 / √(69) + (19)²
14. (76)² / 52 * √(7) / (81)²
15. √(3) / √(81) / 65 * (4)² * (95)²
16. 38 * 45 + √(92) * (15)²
17. √(61) - 81 - √(53) / (87)²

@ -0,0 +1,36 @@
1. (51)² - 95 - √(85) + (20)² + 98
2. (86)² / 37 - √(42) - 44 + 52
3. √(42) - √(58) / (23)² / √(10)
4. (40)² - 50 - (61)²
5. (90)² - (21)² * 3
6. 15 * √(58) + (56)²
7. 7 / 43 - √(94)
8. 52 - 85 - 64 * (59)²
9. (45)² / 53 / (53)² + 76 * (33)²
10. √(11) + (52)² * (52)²
11. √(61) + 22 * (24)² / √(31) - √(85)
12. 20 - √(79) - (100)²
13. √(5) * (29)² / 75 * √(75)
14. √(98) + 49 * 32 + √(22)
15. (93)² - √(83) / (80)² + √(29) + 57
16. (28)² * √(58) / 93
17. (75)² / √(81) + (40)²
18. √(86) * 8 * 20 / 33 * (91)²

@ -0,0 +1,38 @@
1. 42 * 45 - (37)²
2. 90 / (84)² + 13 / √(79)
3. 66 - √(84) * (97)²
4. 35 * √(33) + (4)² - √(32) / √(5)
5. 65 * 98 * (53)² + 95 - 35
6. (13)² - 59 + 59 * √(39) / √(80)
7. 2 + (21)² + (53)²
8. (54)² / 44 * (41)² - 2 * √(17)
9. √(32) / 7 - (100)² - √(39) + 95
10. 70 * 85 * √(87)
11. 90 * (33)² + √(86)
12. (19)² / √(83) / (91)²
13. √(46) + 89 - 93
14. √(62) - (53)² + √(13) / (98)²
15. √(2) * √(59) / 71 + (13)² + √(87)
16. 82 / √(83) + 51 - 80
17. 46 + (41)² / 27 * 72 + (98)²
18. √(15) / (52)² + √(6) * (62)²
19. √(2) - 34 - (47)²

@ -0,0 +1,22 @@
1. cos(90°)
2. 30 / sin(180)
3. 55 / tan(218°)
4. 17 * cos(45°)
5. tan(153)
6. 82 / (78 + 50 /) cos(300)
7. 67 + cos(180°) + 20 / 79
8. sin(45°) * 89 * 56 + 58 / tan(210°)
9. sin(300)
10. sin(120°) / 40 - (tan(315) +) tan(195°)
11. 21 - sin(120°)

@ -0,0 +1,24 @@
1. 79 - 53 * sin(0)
2. 80 - 86 - 58 / sin(300°)
3. tan(94°) * 65
4. sin(300) - sin(180) - (58 /) tan(330°) * 51
5. sin(30°) + 56 + 22
6. sin(330) - 10
7. cos(342) / cos(60°) / tan(315°)
8. sin(90) + 14
9. 37 / tan(240°) / cos(330°) - 15 / tan(180°)
10. cos(240) - 38 + cos(315°)
11. sin(0°) + 5 - sin(60°) - cos(60°) / 38
12. sin(178)

@ -0,0 +1,24 @@
1. 29 / 11 + tan(270) - sin(30) * 61
2. (cos(270) * sin(30) + sin(150) -) 88
3. tan(225°)
4. 29 - tan(150)
5. tan(270) * 82 * tan(150°)
6. 74 + cos(270) - 27 * 45 / 86
7. cos(61°) - tan(360) - (29 +) 57
8. (27 / tan(330°) +) 8 * sin(30°) * 57
9. (93 + tan(315°) *) 86
10. sin(360)
11. tan(30°) * 73
12. tan(340°) - (70 *) 80

@ -0,0 +1,26 @@
1. 14 + tan(330°)
2. sin(300°) / 49
3. sin(30°) - 39 / 24 - 70
4. cos(210)
5. (sin(180°) / 98 -) cos(235) - cos(61°) - 75
6. sin(150) - 73 + 58
7. sin(150°) - 6 - tan(180) + sin(225°) - 64
8. tan(315) - sin(315°) + tan(45) * (69 +) sin(317)
9. tan(63) / sin(30)
10. 60 * tan(45)
11. tan(135°) / 63 / sin(270) + 84 + 64
12. 48 / tan(315°) / 81 + sin(360°)
13. sin(45°)

@ -0,0 +1,28 @@
1. sin(179°) + 8 - (90 /) 81
2. 66 + tan(300°) / 23 - 59 * 46
3. 70 - 18 + (tan(56) / cos(180) -) 2
4. (29 / 11 * 76 -) cos(360)
5. cos(210) - cos(210°) + 38
6. cos(30°) / 72 / 45
7. (tan(135°) -) 98 + 28
8. 66 * cos(315) * 25 - 68
9. sin(204)
10. (sin(0) - 2 *) 9
11. 17 + tan(0)
12. cos(117°) * sin(240) + cos(313) - 59 - 72
13. tan(45) * 15 / tan(135°) - (tan(90°) +) 75
14. tan(330)

@ -0,0 +1,30 @@
1. tan(185°)
2. cos(180°)
3. cos(30°)
4. (sin(270°) +) sin(150°) / tan(19°)
5. cos(180°) * 17 + 37 - (24 -) 1
6. tan(120°) / sin(30) / 46
7. 87 / tan(120°) + 100 - cos(210°)
8. tan(90°) - 87 - 10
9. (cos(315°) *) 45 - cos(315) + 38
10. sin(184°) - 81
11. cos(60°)
12. 36 - tan(30) * 11 / 13
13. tan(45) / sin(180) - (64 -) 43 + tan(111)
14. 35 * (5 +) tan(300°) * 93
15. tan(315°)

@ -0,0 +1,32 @@
1. sin(210) - 48 * 54
2. tan(150)
3. 30 - tan(0°)
4. 14 + cos(60°) * sin(270) * 8 + 60
5. 38 - (57 /) sin(270)
6. (30 -) sin(0°) - 94 - 77 / sin(60)
7. 15 + sin(180) + 32 / cos(120)
8. tan(275°) * 75 + tan(30°) - tan(270) + tan(30)
9. tan(46°)
10. sin(225°) - 1
11. (32 /) cos(156) + 95
12. sin(300)
13. sin(30°) / 65 + cos(52) / cos(0)
14. 84 * (37 *) 10 - cos(210°)
15. 81 / (72 - 69 -) cos(0) - 20
16. cos(210) / 12 / 61

@ -0,0 +1,34 @@
1. cos(180) * 37
2. cos(279) / 95
3. tan(180°)
4. sin(219) / 92 / (8 *) 10
5. tan(240°) / (74 - 35 -) 56 + 84
6. 86 / 28 + (98 *) cos(135°)
7. sin(150°) + 1
8. sin(191°)
9. tan(210) + (tan(148) -) 82 + 11
10. 9 / 95 + tan(150)
11. 93 - cos(56°) * 34 * 94
12. cos(360°)
13. tan(120°)
14. sin(120°)
15. (84 - sin(318°) *) sin(22)
16. 65 / (sin(270) + sin(30°) + 6 +) cos(90)
17. tan(45°) / 73

@ -0,0 +1,36 @@
1. cos(143°) + (tan(0°) /) sin(210°)
2. tan(90°) / tan(353°) / (tan(90°) *) 11 * 40
3. tan(90°) / tan(0) / 59 + sin(45°) - cos(360)
4. tan(330°) / tan(150°) + sin(210°) / 80 + 78
5. 92 + 35 / sin(360°) - cos(274)
6. (cos(240°) +) 57 * 81
7. 24 + (81 -) cos(330°) / sin(150)
8. cos(300) * (30 /) 39
9. 46 * (tan(315°) -) 92
10. cos(30) + tan(150°) * 2 * 17
11. tan(60) * 38 * cos(240)
12. 87 / tan(45°)
13. tan(330°)
14. cos(120°) / 80
15. 60 * 28 / tan(240°) * 43
16. cos(330) + 59
17. 39 * (sin(135°) /) 78
18. 29 - (cos(150°) *) 42

@ -0,0 +1,38 @@
1. sin(0°)
2. sin(330°)
3. (cos(90°) * 2 /) 24
4. 23 - 47 - sin(38°) / cos(279)
5. tan(60°) / 24 * 71
6. (8 / cos(60°) - sin(240°) * 24 *) cos(270°)
7. 100 - sin(180) / 49 + tan(225) * cos(180°)
8. sin(270) * 38
9. 89 - tan(330°)
10. tan(360°) - 72 / 30 / 72 + 64
11. tan(360) + cos(352) / 80 + 65
12. 41 + (tan(300°) * sin(240) -) 5
13. 88 + 28 * 45 / tan(30) - 2
14. sin(45°) - 60 * (sin(360°) +) sin(251)
15. tan(135) * 10 + 44 - 33
16. sin(135°) + 78 - (54 -) sin(0°)
17. 30 - 57 + tan(225)
18. cos(150°) / tan(149°) * sin(225°)
19. 85 * 32 - cos(120°)

@ -0,0 +1,40 @@
1. tan(135) / (19 - 33 +) 40
2. tan(300) / 15
3. sin(270)
4. cos(30) - sin(90°) - 50 + 46
5. 4 / sin(135°)
6. 15 / cos(315)
7. cos(315°) + 63 * 9
8. 72 / sin(0) + 5 / cos(90°) * sin(330°)
9. 24 * tan(315°) - sin(135)
10. (sin(315°) -) 39 / tan(270)
11. tan(210°) - (51 -) 79 + 81 / tan(150°)
12. cos(255)
13. sin(240°) - (31 - 17 /) tan(225)
14. 9 * tan(300°)
15. tan(227) + sin(225) * 99 - (28 +) 88
16. 55 * tan(210) * 55 + 35
17. cos(60)
18. tan(300) / cos(360) - tan(45°) + 35
19. 53 + (49 *) 92 * tan(225)
20. (96 +) 70 * tan(60)

@ -0,0 +1,24 @@
1. (66 - 35 - 2 / 66)
2. 81 + 91 * 53 * 98 * 93
3. 86 / 63 + 48 * 73 + 35
4. 12 - 69
5. (82 * 66 / 31)
6. 90 / (16 / 95)
7. 44 * 67 * 57
8. 84 / 33 + 47 - 40
9. (63 - 49 / 35 /) 39 + 37
10. 75 / 21 * 11
11. 11 * 30 / 73
12. 93 / 27

@ -0,0 +1,46 @@
1. 24 - 37 + 96 * 83
2. 60 * 76 - 82 + 68
3. 9 + 77 - 89 - 72
4. 94 + 89
5. 55 * 47
6. 34 / 86 - 40 + 56
7. 29 / 71 - 75
8. 76 + 99
9. 15 / 49 + 95 - 17
10. 54 * 45
11. 68 * 72
12. 57 + (6 / 88 - 75)
13. (9 + 3 + 18)
14. 47 - 73
15. 6 / 52 * (94 - 38)
16. 52 / 97 * 76 / 53 - 47
17. 40 + 44 * 17 / 90 + 22
18. 84 - (37 - 69 / 39)
19. 40 / 44 - 73 + 22 * 51
20. 11 - 25 * 20 + 8
21. 24 - 92 - 94 / 74 - 56
22. 38 + 58
23. 6 * 23 / 41 / 85

@ -0,0 +1,24 @@
1. 90 - 99 + 90
2. 47 - 37 / 88 * 85
3. 6 - (18 - 65)
4. 20 / 70 - 13
5. (66 - 10 / 41 / 14)
6. 76 / (72 - 21)
7. 14 / (91 / 74 *) 80
8. 96 / 70 - 84
9. 71 * 18 / 6 - 47
10. 75 / 5 * 68
11. 14 - 10 + 78
12. 48 * 70 * 6 * 69

@ -0,0 +1,46 @@
1. (42 / 53 /) 80
2. 69 - 60 * 29 / 36
3. 81 / 49
4. 11 / 51 * 11 / 65 + 36
5. 42 - 100 * 1
6. 90 - 40 * 94
7. 48 / 54 * 2 + 12 - 100
8. 37 - 43 / 62 - (62 * 45)
9. 45 / 78 - 100 / 15
10. 12 - 73 / (10 * 11)
11. 73 - 64 * 97
12. 83 / 19 - 96
13. 2 / 87
14. (44 + 59 -) 89
15. 36 * 5 * 54 - (70 + 64)
16. 55 * 51 * 60
17. (58 / 37 / 12 -) 6 - 76
18. (80 + 59 - 2)
19. 39 * 92
20. 27 * 60 - 71
21. 81 / 13 - (83 + 87 *) 87
22. 31 / 36 * 20 - 21 - 1
23. 72 - 31 * 96 + 18 + 94

@ -0,0 +1,24 @@
1. √(75) - √(72) * (10)² + (26)²
2. 80 * √(75) - √(17) / 33 / 37
3. (20)² * 87 - (44)² * 9
4. (100)² + 2 * 41 * √(48) - (38)²
5. √(50) - (79)² / 7 / 18 - √(37)
6. √(56) - √(15) - (86)² + (58)²
7. (68)² + (98)² / 58
8. (96)² + √(40) - (4)² + 12
9. 42 - 22 / √(41) + (53)²
10. 94 - 69 / (57)²
11. √(59) / 51 - 55 - √(98)
12. √(81) * 73 / 85

@ -0,0 +1,46 @@
1. √(12) - (93)² * √(16)
2. √(72) / √(35) * (76)² / √(79) * √(74)
3. √(94) * 60 + 63 + (68)²
4. 28 - 24 / √(27) - 53
5. √(48) + (71)² * 44
6. 82 - √(83) + 19
7. √(83) / 63 / 92 / 35 / 73
8. (49)² * (9)² * √(93) * 52 - 28
9. (43)² / (71)² * (72)² - 13
10. 98 / √(77) / 23 + 15 / (63)²
11. √(54) * (17)² + √(75) / √(42)
12. √(28) + (32)² + 29
13. 56 - √(57) - 28 * √(60) / √(8)
14. 8 / √(20) - √(25) + 82
15. √(34) * √(52) - √(21) - (13)² * 90
16. 76 + √(82) + 73 * (39)²
17. √(50) - 77 / (96)² - 90 + √(49)
18. (81)² / (9)² / √(71) - 81 - √(98)
19. 50 - 16 / √(31) / √(98) / 26
20. (5)² * 88 * √(56) * (20)² - (97)²
21. 47 / (83)² + (67)² / 88
22. 39 / √(14) - 36 + 87 + 1
23. 84 + (87)² / 56

@ -0,0 +1,24 @@
1. 73 + (88)² - 86
2. (28)² / 82 + (91)² - 6 * (51)²
3. √(19) / (36)² + √(24) + √(96)
4. (55)² + (5)² + 16 / (37)² * 18
5. (76)² - 62 * √(2) / (93)²
6. (30)² * (42)² - 33
7. 40 - √(94) + (39)²
8. √(30) - (67)² + √(60)
9. (56)² - (75)² + (31)² + (12)²
10. (10)² * 24 * 4 - 26
11. 47 * 100 / √(55) / (58)² - (99)²
12. 55 + (73)² * (48)² * (88)²

@ -0,0 +1,46 @@
1. √(7) / √(49) * (94)² + 85 / 90
2. (64)² + √(92) * √(70) + (46)²
3. (25)² * 49 - (25)² - (6)²
4. 71 * √(18) / (19)² + √(4) / (40)²
5. (27)² * √(41) / 47 * 32 - (51)²
6. (93)² * 25 * 67 - √(89)
7. √(99) / 80 + (39)²
8. √(10) - 2 - 29 / (45)²
9. (17)² - (82)² * (95)²
10. 84 + 99 - √(73)
11. √(82) - 73 / √(26) * √(9) + √(95)
12. √(64) - √(29) * (13)² * √(38) + 39
13. (43)² / √(85) - 68 - 93
14. (76)² * 15 * (96)²
15. √(22) - 49 * 9 + 24
16. √(94) * 97 - (81)²
17. (33)² / √(27) * √(70) + (3)²
18. √(1) - (44)² * √(48)
19. 19 + 19 - (91)² * √(51) / 50
20. (39)² - 22 * √(14) / (4)²
21. √(15) / 40 / √(64)
22. √(71) * √(68) - 32 / √(85) - 87
23. 83 * (86)² - √(88)

@ -0,0 +1,24 @@
1. (14)² * (77)² / (39)² / 89 * 87
2. 75 * 38 - √(22) + 13 / (14)²
3. (96)² * 1 - (45)²
4. 66 + 84 * 89 * (64)² + √(99)
5. 79 - 25 + (70)²
6. 79 + (75)² + (35)² / 17 / 59
7. 47 + (77)² - √(23)
8. √(32) + (56)² - √(71) * (100)²
9. √(11) + √(62) * √(67) * (26)² / √(54)
10. √(23) + √(2) + 68
11. 31 - (57)² + (71)²
12. √(22) / 92 - 1

@ -0,0 +1,46 @@
1. 36 / √(62) + (27)²
2. (16)² - 5 - √(21)
3. √(42) / 39 * √(21) - 15
4. 11 - (29)² * 96 - 93
5. (73)² - 88 + √(70)
6. 70 + 16 - 59 / (52)² + √(97)
7. 88 / √(39) + √(68) + (35)²
8. 94 / √(63) / √(3)
9. (38)² * 44 + 89
10. (66)² * (38)² + 94 / (70)² - 88
11. (82)² / (68)² / 60 + 3
12. √(36) * 84 * √(81) * √(4)
13. 15 / 21 - √(66) * (5)²
14. 55 / (19)² - √(64)
15. √(24) * 42 - 65
16. 80 + 74 + √(76) - 75 - (22)²
17. 78 - √(65) + (18)²
18. 6 * 78 - 95 / (21)² / 58
19. √(20) / (33)² - 39 * (18)²
20. (24)² + 7 - 86 + √(49) + √(94)
21. (52)² - (84)² / 61
22. (85)² - √(83) * √(75) / (43)² - (80)²
23. √(20) - √(99) + (78)²

@ -0,0 +1,24 @@
1. tan(60)
2. cos(210) / 84 - (tan(176) + 39 /) 22
3. cos(210°) - 43 / 3 * 20
4. (98 / sin(315) * tan(119°) *) 28
5. 56 / 55 * 60 + cos(110) - sin(150°)
6. tan(120) - 46 / sin(315°) + 58
7. 45 / sin(210)
8. tan(360) + sin(60)
9. 52 + sin(336) + sin(16)
10. sin(210°) + 88
11. 77 + 12 / tan(120°)
12. (11 /) 38 + cos(135) * 16

@ -0,0 +1,46 @@
1. sin(180°) * 89
2. 6 - tan(30°) - tan(210)
3. 61 * sin(303°)
4. (tan(45°) /) 97 * 66
5. (75 -) cos(161°) / 27 + 51 + tan(330)
6. 100 - cos(135°)
7. (tan(90°) +) 66 / 29
8. sin(30°) + sin(150) * 5
9. sin(0°) / 15
10. tan(340) / 62
11. sin(213°) / 74
12. tan(60°)
13. (cos(330) * tan(210) / 7 -) 50 * 83
14. 73 - tan(315°)
15. 57 / tan(210°) + 57 - 91 / 90
16. 96 * cos(225)
17. 6 * sin(270°)
18. sin(240)
19. sin(300°) - cos(210°)
20. 33 * (40 - 78 / sin(250) -) cos(183°)
21. 95 * 23 + sin(150) - (52 +) 47
22. cos(178°) / tan(135°)
23. 98 * cos(315°)

@ -0,0 +1,24 @@
1. 84 * cos(90°)
2. sin(0°) - (48 +) 32
3. 53 * 83 / sin(90°)
4. 15 + tan(240) + 31 + sin(86°) / 18
5. cos(225)
6. tan(0°) + 32 + sin(315) / 87 * tan(150)
7. sin(240)
8. cos(275)
9. 87 * 87 + 53 + tan(240)
10. tan(300°) - (cos(30°) /) 65
11. (cos(78°) -) sin(270°) * 13
12. 53 - 41 * cos(210°) * 6

@ -0,0 +1,46 @@
1. sin(30°) / sin(30) + 76 + 53
2. (tan(240) + 56 +) 43
3. 17 + cos(303°)
4. cos(322°) - 29 - (37 -) 7
5. tan(30)
6. sin(225) * cos(180°) - 40 + 17
7. (tan(259) - 23 +) 71
8. tan(212)
9. tan(30)
10. 2 / cos(0°)
11. cos(150) + 25
12. sin(30) + 5 / cos(45)
13. 81 / 94 / sin(120) / cos(60) / cos(180°)
14. 88 * (75 -) cos(90) / 62
15. cos(270) + 94 + 20 * 33 / 70
16. tan(180) * 94
17. 22 * sin(210°)
18. tan(120) * 73
19. sin(315)
20. (4 - cos(300°) /) tan(315) / cos(252)
21. sin(300) / 86
22. (31 - cos(0°) -) 66
23. 65 * sin(360) + tan(148°) * cos(315°)

@ -0,0 +1,24 @@
1. cos(225)
2. 100 * 17 * tan(30°) + sin(18)
3. 25 + tan(108°) + (cos(150°) -) tan(45°)
4. (cos(357) /) 47 * tan(45°) - 92 / 74
5. sin(150°)
6. cos(0) + (74 -) cos(319)
7. cos(90°) * sin(120°)
8. 62 + tan(330°) / tan(150) * sin(360°) / 6
9. cos(300°)
10. cos(60°) + (tan(210) *) 34
11. 35 - 40 - cos(120°) + (25 -) 80
12. (79 -) cos(240°) - tan(135°)

@ -0,0 +1,46 @@
1. 18 * (59 *) sin(315)
2. tan(300) / (85 * 29 -) 36
3. 56 + cos(330°)
4. (tan(90) * 79 / 38 +) 11 - 61
5. tan(300)
6. 99 + cos(193) + 6 - 43
7. tan(240°) * 29 - 68
8. (cos(180) /) cos(90°) / sin(120) / 6
9. cos(90)
10. cos(60°)
11. cos(210°)
12. sin(45) / 6
13. 26 / tan(13)
14. cos(146)
15. (cos(90) * 32 /) 32
16. cos(240°) / cos(150) - (tan(294°) +) cos(270) / 69
17. cos(210) + 57 + 84 - cos(210°) * cos(170°)
18. 79 + sin(135) / (16 /) 82
19. tan(360)
20. cos(360°) / 72
21. 31 / 52 - tan(270°) - 78 * cos(135)
22. tan(0) + (6 /) 84
23. (sin(192) - 92 /) 5

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 项目坐标信息 -->
<groupId>com.math</groupId>
<artifactId>math-test-generator</artifactId>
<version>1.0.0</version>
<!-- 项目属性配置 -->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 指定主类 -->
<main.class>Main</main.class>
</properties>
<!-- 项目依赖 -->
<dependencies>
<!-- JUnit测试框架 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- 构建配置 -->
<build>
<plugins>
<!-- 编译器插件配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 创建可执行JAR的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<!-- 指定主类 -->
<mainClass>${main.class}</mainClass>
<!-- 添加类路径 -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 依赖拷贝插件,用于将依赖复制到指定目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- 程序集插件创建包含所有依赖的fat jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<!-- 创建一个包含所有依赖的jar -->
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>math-test-generator</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,58 @@
<<<<<<< HEAD
package entity;
/**
*/
public class Question {
private final int number; // 题号
private final String content; // 题目内容(数学表达式)
/**
@param number 1
@param content
*/
=======
package main.java.entity;
//题目类定义
public class Question {
private int number;
private String content;
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
public Question(int number, String content) {
this.number = number;
this.content = content;
}
<<<<<<< HEAD
// Getter方法
public int getNumber() { return number; }
public String getContent() { return content; }
/**
toString
.
@return
*/
@Override
public String toString() {
return number + ". " + content;
}
}
=======
//获取题目信息
public int getNumber() {return number;}
public String getContent() {return content;}
@Override
//重写toString方法返回number与content
public String toString() {
return number + " " + content;
}
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,49 @@
<<<<<<< HEAD
package entity;
/**
//
final
*/
public class User {
private final String username; // 用户名
private final String password; // 密码
private final String type; // 用户类型:小学、初中、高中
/**
@param username
@param password
@param type
*/
=======
package main.java.entity;
//用户类定义
public class User {
private String username;
private String password;
private String type;
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
public User(String username, String password, String type) {
this.username = username;
this.password = password;
this.type = type;
}
<<<<<<< HEAD
// Getter方法
public String getUsername() { return username; }
public String getPassword() { return password; }
public String getType() { return type; }
}
=======
//获得用户信息
public String getUsername() {return username;}
public String getPassword() {return password;}
public String getType() {return type;}
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,34 @@
<<<<<<< HEAD
package factory;
/**
使
*/
public class QuestionFactory {
/**
@param type
@return
@throws IllegalArgumentException
*/
public static QuestionGenerator createGenerator(String type) {
switch (type) {
case "小学":
return new generator.PrimaryQuestionGenerator();
case "初中":
return new generator.JuniorQuestionGenerator();
case "高中":
return new generator.SeniorQuestionGenerator();
default:
throw new IllegalArgumentException("不支持的题目类型: " + type);
}
}
=======
package main.java.factory;
public class QuestionFactory {
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
}

@ -0,0 +1,37 @@
<<<<<<< HEAD
package factory;
import entity.Question;
import java.util.List;
/**
*/
public interface QuestionGenerator {
/**
@param count
@return
*/
List<Question> generateQuestions(int count);
/**
@return
*/
Question generateQuestion();
/**
@return //
*/
String getType();
}
=======
package main.java.factory;
public class QuestionGenerator {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,244 @@
<<<<<<< HEAD
package generator;
import entity.Question;
import factory.QuestionGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
<p>(²)()
*/
public class JuniorQuestionGenerator implements QuestionGenerator {
private static final String[] BINARY_OPERATORS = {"+", "-", "*", "/"};
private static final String[] UNARY_OPERATORS = {"²", "√"};
private static final int MIN_OPERAND_COUNT = 3;
private static final int MAX_OPERAND_COUNT = 5;
private static final int MIN_OPERAND_VALUE = 1;
private static final int MAX_OPERAND_VALUE = 100;
private static final double UNARY_OPERATOR_PROBABILITY = 0.6;
private final Random random;
/**
*/
public JuniorQuestionGenerator() {
this.random = new Random();
}
/**
@param count
@return
*/
@Override
public List<Question> generateQuestions(int count) {
List<Question> questions = new ArrayList<>();
for (int i = 0; i < count; i++) {
questions.add(generateQuestion());
}
return questions;
}
/**
<p>
@return
*/
@Override
public Question generateQuestion() {
String expression;
boolean hasAdvancedOperator;
boolean hasBinaryConnection;
// 循环生成直到满足条件
do {
expression = generateValidExpression();
hasAdvancedOperator = containsAdvancedOperator(expression);
hasBinaryConnection = hasBinaryOperatorConnection(expression);
} while (!hasAdvancedOperator || !hasBinaryConnection);
return new Question(0, expression);
}
/**
*
*
* @return "初中"
*/
@Override
public String getType() {
return "初中";
}
/**
*
*
* <p>
*
* @return
*/
private String generateValidExpression() {
int operandCount = random.nextInt(MAX_OPERAND_COUNT - MIN_OPERAND_COUNT + 1) + MIN_OPERAND_COUNT;
StringBuilder expression = new StringBuilder();
// 添加第一个操作数,可能应用一元运算符
expression.append(generateOperandWithPossibleUnaryOperator());
// 添加后续操作数和运算符
for (int i = 1; i < operandCount; i++) {
expression.append(" ").append(generateBinaryOperator()).append(" ");
expression.append(generateOperandWithPossibleUnaryOperator());
}
return expression.toString();
}
/**
*
*
* @return
*/
private String generateOperandWithPossibleUnaryOperator() {
String operand = generateOperand();
// 根据概率决定是否应用一元运算符
if (random.nextDouble() < UNARY_OPERATOR_PROBABILITY) {
String operator = UNARY_OPERATORS[random.nextInt(UNARY_OPERATORS.length)];
return applyUnaryOperator(operand, operator);
}
return operand;
}
/**
*
*
* @param operand
* @param operator
* @return
*/
private String applyUnaryOperator(String operand, String operator) {
switch (operator) {
case "²":
return "(" + operand + ")²";
case "√":
return "√(" + operand + ")";
default:
return operand;
}
}
/**
* 1-100
*
* @return
*/
private String generateOperand() {
return String.valueOf(random.nextInt(MAX_OPERAND_VALUE) + MIN_OPERAND_VALUE);
}
/**
*
*
* @return
*/
private String generateBinaryOperator() {
return BINARY_OPERATORS[random.nextInt(BINARY_OPERATORS.length)];
}
/**
*
*
* @param expression
* @return truefalse
*/
private boolean containsAdvancedOperator(String expression) {
return expression.contains("²") || expression.contains("√");
}
/**
*
*
* <p>
*
* @param expression
* @return truefalse
*/
private boolean hasBinaryOperatorConnection(String expression) {
// 如果表达式包含高级运算符,检查是否有足够的二元运算符连接
if (containsAdvancedOperator(expression)) {
int binaryOperatorCount = countBinaryOperators(expression);
// 至少需要1个二元运算符来连接操作数
return binaryOperatorCount >= 1;
}
return false;
}
/**
*
*
* @param expression
* @return
*/
private int countBinaryOperators(String expression) {
int count = 0;
for (String operator : BINARY_OPERATORS) {
// 简单的计数方法,实际可能需要更复杂的解析
int index = expression.indexOf(operator);
while (index >= 0) {
count++;
index = expression.indexOf(operator, index + 1);
}
}
return count;
}
/**
*
*
* <p>
*
* @return
*/
private String generateGuaranteedValidExpression() {
StringBuilder expression = new StringBuilder();
// 至少生成3个操作数以确保有连接
int operandCount = random.nextInt(MAX_OPERAND_COUNT - MIN_OPERAND_COUNT + 1) + MIN_OPERAND_COUNT;
// 第一个操作数:普通操作数
expression.append(generateOperand());
expression.append(" ").append(generateBinaryOperator()).append(" ");
// 第二个操作数:应用高级运算符
String advancedOperand = generateOperand();
String unaryOperator = UNARY_OPERATORS[random.nextInt(UNARY_OPERATORS.length)];
expression.append(applyUnaryOperator(advancedOperand, unaryOperator));
// 如果有更多操作数,继续添加
for (int i = 2; i < operandCount; i++) {
expression.append(" ").append(generateBinaryOperator()).append(" ");
// 随机决定是否应用一元运算符
if (random.nextBoolean()) {
expression.append(generateOperandWithPossibleUnaryOperator());
} else {
expression.append(generateOperand());
}
}
return expression.toString();
}
}
=======
package main.java.generator;
public class JuniorQuestionGenerator {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,208 @@
<<<<<<< HEAD
package generator;
import entity.Question;
import factory.QuestionGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
<p>
1-100
*/
public class PrimaryQuestionGenerator implements QuestionGenerator {
private static final String[] OPERATORS = {"+", "-", "*", "/"};
private static final int MIN_OPERAND_COUNT = 2;
private static final int MAX_OPERAND_COUNT = 5;
private static final int MIN_OPERAND_VALUE = 1;
private static final int MAX_OPERAND_VALUE = 100;
private static final double PARENTHESIS_PROBABILITY = 0.3;
private final Random random;
/**
*/
public PrimaryQuestionGenerator() {
this.random = new Random();
}
/**
@param count
@return
*/
@Override
public List<Question> generateQuestions(int count) {
List<Question> questions = new ArrayList<>();
for (int i = 0; i < count; i++) {
questions.add(generateQuestion());
}
return questions;
}
/**
<p>2-51-100
@return
*/
@Override
public Question generateQuestion() {
// 生成基础表达式(不带括号)
String baseExpression = generateBaseExpression();
// 随机决定是否添加括号
String finalExpression = maybeAddParentheses(baseExpression);
return new Question(0, finalExpression);
}
/**
@return "小学"
*/
@Override
public String getType() {
return "小学";
}
/**
@return
*/
private String generateBaseExpression() {
int operandCount = random.nextInt(MAX_OPERAND_COUNT - MIN_OPERAND_COUNT + 1) + MIN_OPERAND_COUNT;
StringBuilder expression = new StringBuilder();
// 添加第一个操作数
expression.append(generateOperand());
// 添加后续操作数和运算符
for (int i = 1; i < operandCount; i++) {
expression.append(" ").append(generateOperator()).append(" ");
expression.append(generateOperand());
}
return expression.toString();
}
/**
@param expression
@return
*/
private String maybeAddParentheses(String expression) {
// 只有当操作数大于2时才考虑添加括号
if (countOperands(expression) > 2 && random.nextDouble() < PARENTHESIS_PROBABILITY) {
return addParentheses(expression);
}
return expression;
}
/**
<p>
@param expression
@return
*/
private String addParentheses(String expression) {
String[] parts = expression.split(" ");
// 如果表达式太短,直接为整个表达式添加括号
if (parts.length <= 3) {
return "(" + expression + ")";
}
// 随机选择括号的起始位置(操作数的位置)
int startPos = random.nextInt(parts.length / 2) * 2; // 确保在操作数位置
// 随机选择括号的长度包含的操作数数量至少2个
int maxLength = (parts.length - startPos) / 2 + 1;
int length = random.nextInt(maxLength - 1) + 2; // 至少2个操作数
// 计算结束位置
int endPos = startPos + (length * 2 - 1);
if (endPos >= parts.length) {
endPos = parts.length - 1;
}
// 构建带括号的表达式
StringBuilder result = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
if (i == startPos) {
result.append("(");
}
result.append(parts[i]);
if (i == endPos) {
result.append(")");
}
if (i < parts.length - 1) {
result.append(" ");
}
}
return result.toString();
}
/**
@param expression
@return
*/
private int countOperands(String expression) {
// 简单估算:操作数数量 ≈ (分割后的数组长度 + 1) / 2
String[] parts = expression.split(" ");
return (parts.length + 1) / 2;
}
/**
1-100
@return
*/
private String generateOperand() {
return String.valueOf(random.nextInt(MAX_OPERAND_VALUE) + MIN_OPERAND_VALUE);
}
/**
@return
*/
private String generateOperator() {
return OPERATORS[random.nextInt(OPERATORS.length)];
}
/**
<p>
@return
*/
private String generateGuaranteedTwoOperandExpression() {
StringBuilder expression = new StringBuilder();
// 确保至少有两个操作数
int operandCount = random.nextInt(MAX_OPERAND_COUNT - MIN_OPERAND_COUNT + 1) + MIN_OPERAND_COUNT;
// 添加第一个操作数
expression.append(generateOperand());
// 添加后续操作数和运算符
for (int i = 1; i < operandCount; i++) {
expression.append(" ").append(generateOperator()).append(" ");
expression.append(generateOperand());
}
return expression.toString();
}
}
=======
package main.java.generator;
public class PrimaryQuestionGenerator {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,234 @@
<<<<<<< HEAD
package generator;
import entity.Question;
import factory.QuestionGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
1-100
1-5
*/
public class SeniorQuestionGenerator implements QuestionGenerator {
private static final String[] BINARY_OPERATORS = {"+", "-", "*", "/"};
private static final String[] TRIGONOMETRIC_FUNCTIONS = {"sin", "cos", "tan"};
private final Random random = new Random();
/**
@param count
@return
*/
@Override
public List<Question> generateQuestions(int count) {
List<Question> questions = new ArrayList<>();
for (int i = 1; i <= count; i++) {
questions.add(generateQuestion());
}
return questions;
}
/**
1-5
1-100
@return
*/
@Override
public Question generateQuestion() {
// 生成1-5个操作数
int operandCount = random.nextInt(5) + 1;
// 确保至少有一个三角函数
int trigFunctionCount = random.nextInt(operandCount) + 1;
// 构建表达式
StringBuilder expression = new StringBuilder();
// 生成第一个操作数或三角函数
if (random.nextBoolean() && trigFunctionCount > 0) {
expression.append(generateTrigonometricFunction());
trigFunctionCount--;
} else {
expression.append(generateOperand());
}
// 生成后续操作数和运算符
for (int i = 1; i < operandCount; i++) {
// 添加运算符
expression.append(" ").append(generateBinaryOperator()).append(" ");
// 决定下一个是普通操作数还是三角函数
if (random.nextBoolean() && trigFunctionCount > 0) {
expression.append(generateTrigonometricFunction());
trigFunctionCount--;
} else {
expression.append(generateOperand());
}
}
// 如果还没有包含三角函数,强制添加一个
if (!expression.toString().contains("sin") &&
!expression.toString().contains("cos") &&
!expression.toString().contains("tan")) {
// 在表达式的随机位置插入一个三角函数
expression = insertTrigonometricFunction(expression.toString());
}
// 随机添加括号以增加复杂度
if (operandCount > 2 && random.nextBoolean()) {
expression = addParentheses(expression.toString());
}
return new Question(0, expression.toString());
}
/**
@return "高中"
*/
@Override
public String getType() {
return "高中";
}
/**
1-100
@return
*/
private int generateOperand() {
return random.nextInt(100) + 1;
}
/**
@return
*/
private String generateBinaryOperator() {
return BINARY_OPERATORS[random.nextInt(BINARY_OPERATORS.length)];
}
/**
@return
*/
private String generateTrigonometricFunction() {
String function = TRIGONOMETRIC_FUNCTIONS[random.nextInt(TRIGONOMETRIC_FUNCTIONS.length)];
int angle = generateAngle(); // 生成合适的角度值
// 随机决定是否使用度数符号
if (random.nextBoolean()) {
return function + "(" + angle + "°)";
} else {
return function + "(" + angle + ")";
}
}
/**
使
@return
*/
private int generateAngle() {
// 常见角度值,使三角函数值更合理
int[] commonAngles = {0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 330, 360};
// 80%的概率使用常见角度20%的概率使用随机角度
if (random.nextDouble() < 0.8) {
return commonAngles[random.nextInt(commonAngles.length)];
} else {
return random.nextInt(360) + 1; // 1-360度
}
}
/**
@param expression
@return
*/
private StringBuilder insertTrigonometricFunction(String expression) {
String[] parts = expression.split(" ");
StringBuilder newExpression = new StringBuilder();
// 随机选择一个位置插入三角函数
int insertPosition = random.nextInt(parts.length);
for (int i = 0; i < parts.length; i++) {
if (i == insertPosition) {
// 在选定位置插入三角函数
if (i % 2 == 0) { // 偶数位置是操作数
// 替换操作数为三角函数
newExpression.append(generateTrigonometricFunction());
} else { // 奇数位置是运算符
// 在运算符后添加三角函数
newExpression.append(parts[i]).append(" ").append(generateTrigonometricFunction());
// 跳过下一个操作数
if (i + 1 < parts.length) {
i++;
}
}
} else {
newExpression.append(parts[i]);
}
if (i < parts.length - 1) {
newExpression.append(" ");
}
}
return newExpression;
}
/**
@param expression
@return
*/
private StringBuilder addParentheses(String expression) {
// 简化的括号添加逻辑:为部分表达式添加括号
String[] parts = expression.split(" ");
if (parts.length <= 2) {
return new StringBuilder(expression);
}
// 随机选择括号的起始和结束位置
int start = random.nextInt(parts.length / 2) * 2; // 确保从操作数开始
int end = start + 2 + random.nextInt((parts.length - start) / 2) * 2; // 确保以操作数结束
if (end - start < 2 || end > parts.length) {
return new StringBuilder(expression);
}
StringBuilder result = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
if (i == start) {
result.append("(");
}
result.append(parts[i]);
if (i == end - 1) {
result.append(")");
}
if (i < parts.length - 1) {
result.append(" ");
}
}
return result;
}
}
=======
package main.java.generator;
public class SeniorQuestionGenerator {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,184 @@
package org.example;
import entity.User;
import entity.Question;
import service.UserService;
import service.QuestionService;
import service.FileService;
import service.ValidationService;
import java.util.List;
import java.util.Scanner;
/**
* -
*
*
*/
public class Main {
// 依赖注入的服务组件
private final UserService userService;
private final QuestionService questionService;
private final FileService fileService;
private final ValidationService validationService;
private final Scanner scanner;
// 当前会话状态
private User currentUser; // 当前登录用户
private String currentType; // 当前题目类型
/**
* -
*/
public Main() {
this.userService = new UserService();
this.validationService = new ValidationService();
this.questionService = new QuestionService(validationService);
this.fileService = new FileService();
this.scanner = new Scanner(System.in);
}
/**
*
* @param args
*/
public static void main(String[] args) {
Main app = new Main();
app.run();
}
/**
*
*
*/
public void run() {
System.out.println("=== 中小学数学卷子自动生成程序 ===");
while (true) {
// 登录阶段
if (!login()) {
continue; // 登录失败,重新尝试
}
// 题目生成阶段
generateQuestionsLoop();
}
}
/**
*
* @return truefalse
*/
private boolean login() {
System.out.print("请输入用户名和密码(用空格隔开): ");
String input = scanner.nextLine().trim();
// 输入验证
if (input.isEmpty()) {
System.out.println("请输入正确的用户名、密码");
return false;
}
String[] credentials = input.split(" ");
if (credentials.length != 2) {
System.out.println("请输入正确的用户名、密码");
return false;
}
String username = credentials[0];
String password = credentials[1];
// 用户认证
User user = userService.authenticate(username, password);
if (user == null) {
System.out.println("请输入正确的用户名、密码");
return false;
}
// 登录成功,设置当前状态
currentUser = user;
currentType = user.getType();
System.out.println("当前选择为" + currentType + "出题");
return true;
}
/**
*
*
*/
private void generateQuestionsLoop() {
while (currentUser != null) {
System.out.print("准备生成" + currentType + "数学题目,请输入生成题目数量(输入-1将退出当前用户重新登录: ");
String input = scanner.nextLine().trim();
// 检查是否是切换命令
if (validationService.isValidSwitchCommand(input)) {
handleSwitchCommand(input);
continue;
}
// 处理数字输入
try {
int count = Integer.parseInt(input);
if (count == -1) {
// 退出当前用户
currentUser = null;
System.out.println("退出当前用户,重新登录...");
break;
}
// 验证题目数量
if (!questionService.validateQuestionCount(count)) {
System.out.println("题目数量应在10-30之间");
continue;
}
// 生成并保存题目
generateAndSaveQuestions(count);
} catch (NumberFormatException e) {
System.out.println("请输入小学、初中和高中三个选项中的一个或有效的数字");
}
}
}
/**
*
* @param command
*/
private void handleSwitchCommand(String command) {
String newType = validationService.extractTypeFromCommand(command);
if (newType.equals("小学") || newType.equals("初中") || newType.equals("高中")) {
currentType = newType;
System.out.println("准备生成" + currentType + "数学题目,请输入生成题目数量");
} else {
System.out.println("请输入小学、初中和高中三个选项中的一个");
}
}
/**
*
* @param count
*/
private void generateAndSaveQuestions(int count) {
try {
// 生成题目
List<Question> questions = questionService.generateQuestions(currentType, count);
// 查重检查
if (fileService.checkDuplicate(currentUser.getUsername(), questions)) {
System.out.println("检测到重复题目,重新生成中...");
generateAndSaveQuestions(count); // 递归重新生成
return;
}
// 保存到文件
String filePath = fileService.saveQuestions(currentUser.getUsername(), questions);
System.out.println("题目已生成并保存到: " + filePath);
} catch (Exception e) {
System.out.println("生成题目时出现错误: " + e.getMessage());
e.printStackTrace(); // 调试用,实际应该记录日志
}
}
}

@ -0,0 +1,74 @@
<<<<<<< HEAD
package service;
import entity.Question;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
*/
public class FileService {
private static final String BASE_DIR = "doc"; // 基础存储目录
/**
@param username
@param questions
@return
@throws IOException
*/
public String saveQuestions(String username, List<Question> questions) throws IOException {
// 创建用户专属文件夹
File userDir = new File(BASE_DIR, username);
if (!userDir.exists()) {
userDir.mkdirs(); // 递归创建目录
}
// 生成基于时间戳的文件名
String filename = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt";
File file = new File(userDir, filename);
// 使用try-with-resources确保文件正确关闭
try (FileWriter writer = new FileWriter(file)) {
for (Question question : questions) {
writer.write(question.toString()); // 写入题目
writer.write("\n\n"); // 题目之间空一行
}
}
return file.getAbsolutePath();
}
/**
@param username
@param newQuestions
@return
*/
public boolean checkDuplicate(String username, List<Question> newQuestions) {
File userDir = new File(BASE_DIR, username);
if (!userDir.exists()) {
return false; // 用户没有历史文件,肯定不重复
}
// 简化的查重实现
// 实际应该1.读取用户所有历史文件 2.解析历史题目 3.比较新题目与历史题目
// 这里为了简化直接返回false表示没有重复
// TODO: 实现完整的查重逻辑
return false;
}
=======
package main.java.service;
public class FileService {
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
}

@ -0,0 +1,59 @@
<<<<<<< HEAD
package service;
import entity.Question;
import factory.QuestionGenerator;
import factory.QuestionFactory;
import java.util.List;
/**
*/
public class QuestionService {
private final ValidationService validationService;
/**
@param validationService
*/
public QuestionService(ValidationService validationService) {
this.validationService = validationService;
}
/**
@param type //
@param count
@return
*/
public List<Question> generateQuestions(String type, int count) {
// 使用工厂创建对应的题目生成器
QuestionGenerator generator = QuestionFactory.createGenerator(type);
// 生成题目
List<Question> questions = generator.generateQuestions(count);
// 为每个题目设置正确的题号
for (int i = 0; i < questions.size(); i++) {
Question question = questions.get(i);
questions.set(i, new Question(i + 1, question.getContent()));
}
return questions;
}
/**
@param count
@return 10-30-1
*/
public boolean validateQuestionCount(int count) {
return validationService.isValidQuestionCount(count);
}
=======
package main.java.service;
public class QuestionService {
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
}

@ -0,0 +1,64 @@
<<<<<<< HEAD
package service;
import entity.User;
import java.util.HashMap;
import java.util.Map;
/**
使使
*/
public class UserService {
private final Map<String, User> users = new HashMap<>(); // 用户名到用户的映射
/**
*/
public UserService() {
initializeUsers();
}
/**
*/
private void initializeUsers() {
// 小学账户
users.put("张三1", new User("张三1", "123", "小学"));
users.put("张三2", new User("张三2", "123", "小学"));
users.put("张三3", new User("张三3", "123", "小学"));
// 初中账户
users.put("李四1", new User("李四1", "123", "初中"));
users.put("李四2", new User("李四2", "123", "初中"));
users.put("李四3", new User("李四3", "123", "初中"));
// 高中账户
users.put("王五1", new User("王五1", "123", "高中"));
users.put("王五2", new User("王五2", "123", "高中"));
users.put("王五3", new User("王五3", "123", "高中"));
}
/**
@param username
@param password
@return null
*/
public User authenticate(String username, String password) {
User user = users.get(username);
// 检查用户是否存在且密码匹配
if (user != null && user.getPassword().equals(password)) {
return user;
}
return null;
}
}
=======
package main.java.service;
public class UserService {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045

@ -0,0 +1,42 @@
<<<<<<< HEAD
package service;
/**
*/
public class ValidationService {
/**
@param count
@return true10-30-1
*/
public boolean isValidQuestionCount(int count) {
return count == -1 || (count >= 10 && count <= 30);
}
/**
@param command
@return true
*/
public boolean isValidSwitchCommand(String command) {
return command.matches("切换为(小学|初中|高中)");
}
/**
@param command
@return //
*/
public String extractTypeFromCommand(String command) {
return command.replace("切换为", "");
}
=======
package main.java.service;
public class ValidationService {
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045
}

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.example.Main
Loading…
Cancel
Save