结对项目
| 课程地址 | https://edu.cnblogs.com/campus/gdgy/CSGrade21-12 |
|---|---|
| 作业要求 | https://edu.cnblogs.com/campus/gdgy/CSGrade21-12/homework/13016 |
| 作业目标 | 进行结队项目尝试、实现小学四则运算的自动生成 |
团队成员
| 姓名 | 学号 |
|---|---|
| 高国豪 | 3121004734 |
| 黄家宝 | 3121004735 |
Github链接
PSP表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 90 | 100 |
| Estimate | 估计这个任务需要多少时间 | 30 | 60 |
| Development | 开发 | 600 | 420 |
| Analysis | 需求分析 (包括学习新技术) | 250 | 120 |
| Design Spec | 生成设计文档 | 50 | 40 |
| Design Review | 设计复审 | 10 | 20 |
| Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 20 | 50 |
| Design | 具体设计 | 60 | 70 |
| Coding | 具体编码 | 240 | 230 |
| Code Review | 代码复审 | 30 | 70 |
| Test | 测试(自我测试,修改代码,提交修改) | 160 | 240 |
| Reporting | 报告 | 80 | 30 |
| Test Repor | 测试报告 | 60 | 50 |
| Size Measurement | 计算工作量 | 70 | 90 |
| Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 60 | 90 |
| 合计 | 1810 | 1690 |
效能分析


代码设计
- 类
| 类名 | 作用 |
|---|---|
| Main | 主函数 |
| Create | 生成题目 |
| Compute | 计算答案 |
| Check | 查重 |
| BuidFile | 生成相关文件 |
- 函数
| 函数名 | 作用 | 归属 |
|---|---|---|
| GCD | 求最大公因数 | Create |
| createFormula | 随机生成算式 | Create |
| typeCheck | 对算式的运算符和算数进行区分,并进行计算 | Compute |
| sim | 化简分数 | Compute |
| Compute | 对算式进行计算 | Compute |
| generation | 生成暂存题集、答案集 | Check |
| isRepeat | 判断算式是否重复 | Check |
| BuildFile | 获取和输出题集、答案集 | BuildFile |
| createExeFile | 生成输出Exercise.txt | BuildFile |
| createAnsFile | 生成输出Answer.txt | BuildFile |
| createGradeFile | 生成输出Grade.txt | BuildFile |
| output | 输出成绩 | BuildFile |
| obtainAnswer | 获取相应文件的信息 | BuildFile |
-
总体流程图
![]()
-
关键代码设计
点击查看代码
public String[] createFormula(int r){
Random random = new Random();
String[] operator = {"+","-","×","÷","="};
String[] totalOperator = new String[1 + random.nextInt(3)];
String[] totalFraction = new String[totalOperator.length + 1];
String formula = new String();
Boolean isFraction = false;
//随机生成操作数
for (int i = 0; i < totalFraction.length; i++){
//随机确定生成整数or分数
int numType = random.nextInt(2);
if(numType == 0) {//生成分数时
int denominator = 1 + random.nextInt(r);
int molecule = random.nextInt(denominator);
int integer = random.nextInt(r + 1);
//化简分数
if (molecule!=0) {
int GCD1 = GCD(denominator, molecule);
denominator /= GCD1;
molecule /= GCD1;
}
//输出最简分数
if (molecule > 0 && integer == 0) {
totalFraction[i] = molecule + "/" + denominator;
isFraction = true;
}
else if (molecule == 0)
totalFraction[i] = String.valueOf(integer);
else {
totalFraction[i] = integer + "'" + molecule + "/" + denominator;
isFraction = true;
}
}else {//生成整数时
int integer = random.nextInt(r+1);
totalFraction[i] = String.valueOf(integer);
}
}
//随机生成运算符
for (int i = 0; i < totalOperator.length; i++){
if(isFraction)
totalOperator[i] = operator[random.nextInt(2)];
else
totalOperator[i] = operator[random.nextInt(4)];
}
//括号
int bracket = totalFraction.length;
if(totalFraction.length != 2)
bracket = random.nextInt(totalFraction.length);
//合成算式
for (int i = 0;i < totalFraction.length; i++) {
if (i == bracket && bracket<totalOperator.length)
formula = formula + "(" + totalFraction[i] + totalOperator[i] ;
else if (i == totalFraction.length - 1 && i == bracket + 1 && bracket<totalOperator.length)
formula = formula + totalFraction[i] + ")" + "=";
else if (bracket<totalOperator.length && i == bracket+1)
formula = formula + totalFraction[i] + ")" + totalOperator[i];
else if (i == totalFraction.length - 1)
formula = formula + totalFraction[i] + "=";
else
formula = formula + totalFraction[i] + totalOperator[i];
}
//检查
Compute compute = new Compute();
String[] answerFormula = compute.typeCheck(formula, 3 * totalOperator.length + 3);
if(answerFormula != null)
return answerFormula;
return null;
}
测试运行
- 测试代码及其结果
- CreateTest
点击查看代码
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class BuildFileTest {
@Test
void BuildFileTest(){//创建题目文件及答案测试
new BuildFile().BuildFile(10,10);
}
@Test
void createGradeFileTest(){//创建分数文件测试
new BuildFile().BuildFile(10,10);
new BuildFile().createGradeFile("..\\Calculator\\Answer.txt","..\\Calculator\\Exercises.txt");
new BuildFile().BuildFile(5,5);
new BuildFile().createGradeFile("..\\Calculator\\Answer.txt","..\\Calculator\\Exercises.txt");
}
}
测试结果

- ComputeTest
点击查看代码
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ComputeTest {
@Test
void typeCheckTest() {
String f = "";
new Compute().typeCheck(f,0);
}
}
测试结果

- CheckTest
点击查看代码
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CheckTest {
@Test
void generationTest(){//生成给定参数的算术表达式
new Check().generation(10,10);
new Check().generation(5,10);
new Check().generation(10,5);
}
}
测试结果

- BuildFileTest
点击查看代码
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class BuildFileTest {
@Test
void BuildFileTest(){//创建题目文件及答案测试
new BuildFile().BuildFile(10,10);
}
@Test
void createGradeFileTest(){//创建分数文件测试
new BuildFile().BuildFile(10,10);
new BuildFile().createGradeFile("..\\Calculator\\Answer.txt","..\\Calculator\\Exercises.txt");
new BuildFile().BuildFile(5,5);
new BuildFile().createGradeFile("..\\Calculator\\Answer.txt","..\\Calculator\\Exercises.txt");
}
}


- 覆盖率
![]()
项目小结
通过此次结队作业,我们深刻认识到个人项目与团队项目的区别:个人项目要个人负责起各个方面的编写;而团队项目则更讲究分工协作,看似团队中的个人只承担了部分责任,实际在项目的执行上却极其考验彼此间的协作和配合。在项目进行初期,我们也曾因工作分配的不合理、彼此间沟通的不顺利而导致项目进度缓慢。但好在在项目进行的过程中这种类似事情的发生有所改善,彼此之间的合作经验和默契也逐渐得到增强。总的来说,经过此次作业,让我们更深刻地认识到团队合作的便利以及在合作中所要注意的事项,也更期待下一次在团队中更多人数的情况下进行项目的开发。


浙公网安备 33010602011771号