作业基本信息
ps:和另外的两个舍友讨论过题目,最终觉得自己一个人也能做完,然后就自己做了
一 gitcode项目地址
二 psp表格
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分 钟) |
Planning |
计划 |
60 |
60 |
Estimate |
估计这个任务需要多少时间 |
300 |
400 |
Development |
开发 |
120 |
200 |
Analysis |
需求分析 (包括学习新技术) |
60 |
60 |
Design Spec |
生成设计文档 |
60 |
60 |
Design Review |
设计复审 |
30 |
30 |
Coding Standard |
代码规范 (为目前的开发制定合适的规范) |
30 |
30 |
Design |
具体设计 |
90 |
60 |
Coding |
具体编码 |
300 |
350 |
Code Review |
代码复审 |
60 |
60 |
Test |
测试(自我测试,修改代码,提交修改) |
60 |
90 |
Reporting |
报告 |
40 |
60 |
Test Repor |
测试报告 |
60 |
60 |
Size Measurement |
计算工作量 |
60 |
60 |
Postmortem & Process Improvement Plan |
事后总结, 并提出过程改进计划 |
120 |
30 |
|
合计 |
1450 |
1610 |
三 效能分析
![请添加图片描述](https://img-blog.csdnimg.cn/55de0ca8fd66436f908321aa5ca0004b.jpeg)
![请添加图片描述](https://img-blog.csdnimg.cn/92f86046ae6e4b54a58e3e1d0c946f83.jpeg)
由性能图可知,耗费最久的还是字符串,这里没有什么需要改进的。
四 思路设计设计实现过程
4.1主要实现的两个功能模块:出题和检查题目对错
- 输入-n和-r控制题目个数和数值范围
- 根据n,r随机生成中缀表示式
- 将中缀表达式生成后缀表达式
- 判断新增表达式与前面生成的是否相同,直到生成数量达到题目要求
- 输出Exercise.txt文件和Answers.txt文件。
- 输入自拟的答案Ans.txt
- 跟Answers.txt进行检验对错
- 输出Grade.txt 结果文件
4.2类的说明
- Main类:主函数,调用其他类
- Expression类:获取输入的操作数和操作符并随机生成表达式
- Calculate类:生成后缀表达式,将中缀表达式转换为后缀表达式
- Check类:实现表达式结果查重功能
- Function类:创建并输出Exercises.txt文件和Answers.txt文件
- CheckQuestion类:检验结果对错并输出Grade.txt文件
4.3流程图
![请添加图片描述](https://img-blog.csdnimg.cn/ff563fef968f423b9bbcdd90ac44a3bc.jpeg)
五 代码说明
package fouroperations;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
while(true) {
System.out.println("请输入生成题目数-n");
Scanner inputn=new Scanner(System.in);
int n=inputn.nextInt();
System.out.println("请输入生成题目参数范围-r");
Scanner inputr=new Scanner(System.in);
int r=inputr.nextInt();
Function makefile = new Function();
makefile.createProblemSet(n,r);
break;
}
}
}
- 将中缀表达式转换为后缀表达式,可以把括号去除,进行遍历的时候,遇到操作符则与栈弹出的两个有理数进行运算即可。
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 hasFraction = false;
for (int i=0;i<totalFraction.length;i++) {
int fractionOrNot = random.nextInt(2);
if (fractionOrNot == 0) {
int integralPart = random.nextInt(r+1);
totalFraction[i] = String.valueOf(integralPart);
} else {
int denominator = 1+random.nextInt(r);
int molecule = random.nextInt(denominator);
int integralPart = random.nextInt(r+1);
if (molecule!=0) {
int commonFactor = commonFactor(denominator, molecule);
denominator /= commonFactor;
molecule /= commonFactor;
}
if (integralPart == 0 && molecule > 0) {
totalFraction[i] = molecule + "/" + denominator;
hasFraction = true;
}
else if (molecule == 0)
totalFraction[i] = String.valueOf(integralPart);
else {
totalFraction[i] = integralPart + "'" + molecule + "/" + denominator;
hasFraction = true;
}
}
}
for (int i=0;i < totalOperator.length;i++) {
if (hasFraction)
totalOperator[i] = operator[random.nextInt(2)];
else
totalOperator[i] = operator[random.nextInt(4)];
}
int choose = totalFraction.length;
if (totalFraction.length != 2 )
choose &