标签:小伙伴 自动生成 level 角色 tin 随机 log mat 新技术
结对编程项目-四则运算 第二周 输出阶段总结博客
学号:20172317 姓名:蒋子行 伙伴第二周博客地址: |
学号:20172327 姓名:马瑞蕃 伙伴第二周博客地址: |
担任角色: 驾驶员:蒋子行 副驾驶:李闻洲 马瑞蕃 |
题目生成的驱动类的编写,整体思路构思
创建一个真分数生成类
创建五个难度类
创建一个中缀转后缀类
创建一个计算后缀表达式的类
创建一个整合类(判断选择那个级别,判断要计算多少道题,判断对的个数及正确率)
一个能生成真分数,并将题目分成五个等级的类
题目生成驱动类:
分析:运用while循环让使用者可以选择1-5五个等级,随机生成相应的题目,每道题目完成后能选择是否继续,若选“n”,程序结束并统计所做的题目个数
QuestionGenerator类,运用switch循环将题目分为五个等级,运用RationalNumber类生成分数,若自动生成的分子大于分母,则交换两者数值
import java.util.Random;
import java.util.Stack;
public class QuestionGenerator {
protected String question, f, suffixOutput;
protected Integer a, b, c;
protected Character operator, operator2, operator3;
private int operatorIndex, operatorIndex2, operatorIndex3;
private double judgeFraction, judgeBrackets;
private char[] opr = {‘+‘, ‘-‘, ‘*‘, ‘/‘};
public QuestionGenerator() {
question = "";
}
public String getQuestion(int level) {
switch (level) {
case 1:
Random generator1 = new Random();
a = generator1.nextInt(10) + 1;
b = generator1.nextInt(10) + 1;
operatorIndex = generator1.nextInt(4);
operator = opr[operatorIndex];
question = a + "" + operator + "" + b + " ";
return question;
case 2:
Random generator2 = new Random();
Random determination1 = new Random();
judgeFraction = determination1.nextFloat();
if (judgeFraction > 0.4) {
a = generator2.nextInt(10) + 1;
operatorIndex = generator2.nextInt(4);
operator = opr[operatorIndex];
RationalNumber fraction = new RationalNumber();
f = fraction.toString();
question = a + "" + operator + "" + f + " ";
} else {
a = generator2.nextInt(10) + 1;
b = generator2.nextInt(10) + 1;
operatorIndex = generator2.nextInt(4);
operator = opr[operatorIndex];
question = a + "" + operator + "" + b + " ";
}
return question;
case 3:
Random generator3 = new Random();
Random determination2 = new Random();
judgeFraction = determination2.nextFloat();
if (judgeFraction > 0.6) {
a = generator3.nextInt(15) + 1;
b = generator3.nextInt(15) + 1;
operatorIndex = generator3.nextInt(4);
operatorIndex2 = generator3.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
RationalNumber fraction = new RationalNumber();
f = fraction.toString();
question = a + "" + operator + "" + b + "" + operator2 + "" + f + " ";
} else {
a = generator3.nextInt(15) + 1;
b = generator3.nextInt(15) + 1;
c = generator3.nextInt(20) + 1;
operatorIndex = generator3.nextInt(4);
operatorIndex2 = generator3.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
question = a + "" + operator + "" + b + "" + operator2 + "" + c + " ";
}
return question;
case 4:
Random generator4 = new Random();
Random determination3 = new Random();
judgeFraction = determination3.nextFloat();
if (judgeFraction > 0.4) {
a = generator4.nextInt(15) + 1;
b = generator4.nextInt(15) + 1;
operatorIndex = generator4.nextInt(4);
operatorIndex2 = generator4.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
RationalNumber fraction = new RationalNumber();
f = fraction.toString();
question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + f + " ";
} else {
a = generator4.nextInt(15) + 1;
b = generator4.nextInt(15) + 1;
c = generator4.nextInt(20) + 1;
operatorIndex = generator4.nextInt(4);
operatorIndex2 = generator4.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + c + " ";
}
return question;
case 5:
Random generator5 = new Random();
Random determination4 = new Random();
judgeBrackets = determination4.nextFloat();
if (judgeBrackets <= 0.5) {
a = generator5.nextInt(15) + 1;
b = generator5.nextInt(15) + 1;
c = generator5.nextInt(15) + 1;
operatorIndex = generator5.nextInt(4);
operatorIndex2 = generator5.nextInt(4);
operatorIndex3 = generator5.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
operator3 = opr[operatorIndex3];
RationalNumber fraction = new RationalNumber();
f = fraction.toString();
question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + f + "" + operator3 + "" + c + " ";
} else {
a = generator5.nextInt(15) + 1;
b = generator5.nextInt(15) + 1;
c = generator5.nextInt(15) + 1;
operatorIndex = generator5.nextInt(4);
operatorIndex2 = generator5.nextInt(4);
operatorIndex3 = generator5.nextInt(4);
operator = opr[operatorIndex];
operator2 = opr[operatorIndex2];
operator3 = opr[operatorIndex3];
RationalNumber fraction = new RationalNumber();
f = fraction.toString();
question = a + "" + operator + "(" + b + "" + operator2 + "" + f + ")" + operator3 + "" + c + " ";
}
return question;
default:
return "错误题目等级!!\n题目等级1-5\n请输入有效的题目等级";
}
}
}
这次的作业大部分是由蒋子行同学完成的,重要的类都是由他编写的,我主要就在开始时提供了一些整体的思路,像是括号问题,去重思路等,编写方面主要靠蒋子行同学,最后我在编写一个驱动类实现题目生成等效果。这次的作业也充分意识到了跟大佬之间的差距,以后还得更加努力的学习。
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) | |
---|---|---|---|---|
Planning | 计划 | 60 | 60 | |
Estimate | 估计这个任务需要多少时间 | 100 | 100 | |
Development | 开发 | 800 | ||
Analysis | 需求分析 (包括学习新技术) | 100 | ||
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 30 | ||
Design UML | 设计项目UML类图 | 50 | ||
Coding | 具体编码 | 30 | ||
Code Review | 代码复审 | 50 | ||
Test | 测试(自我测试,修改代码,提交修改) | 30 | ||
Size Measurement | 计算工作量(实际时间 ) | 30 | ||
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 30 | ||
合计 | 1240 |
标签:小伙伴 自动生成 level 角色 tin 随机 log mat 新技术
原文地址:https://www.cnblogs.com/garolwz/p/9010701.html