20172320 结对编程项目-四则运算 第二周 阶段总结

Posted garolwz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20172320 结对编程项目-四则运算 第二周 阶段总结相关的知识,希望对你有一定的参考价值。

20172320 结对编程项目-四则运算 第二周 阶段总结

结对编程项目-四则运算 第二周 输出阶段总结博客

结对对象:


学号:20172317
姓名:蒋子行
伙伴第二周博客地址:

学号:20172327
姓名:马瑞蕃
伙伴第二周博客地址:

担任角色:
驾驶员:蒋子行
副驾驶:李闻洲 马瑞蕃

小组结对编程的photo:

技术分享图片

项目中自己负责的部分:

题目生成的驱动类的编写,整体思路构思

个人贡献度划分:


创建一个真分数生成类

创建五个难度类

创建一个中缀转后缀类

创建一个计算后缀表达式的类

创建一个整合类(判断选择那个级别,判断要计算多少道题,判断对的个数及正确率)

相关过程的截图

  • 一个能生成真分数,并将题目分成五个等级的类
    技术分享图片
    技术分享图片
    技术分享图片

  • 分析:将题目分成五个等级,每个等级有一个固定的形式,从等级3开始有可能真分数出现,因此这个类还保证了支持真分数,同时还加入了括号
  • 题目生成驱动类:
    技术分享图片
    技术分享图片

  • 分析:运用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请输入有效的题目等级";
        }
    }
    }                                                                                                                                                                                            

代码托管地址

对结对的小伙伴做出评价:

这次的作业大部分是由蒋子行同学完成的,重要的类都是由他编写的,我主要就在开始时提供了一些整体的思路,像是括号问题,去重思路等,编写方面主要靠蒋子行同学,最后我在编写一个驱动类实现题目生成等效果。这次的作业也充分意识到了跟大佬之间的差距,以后还得更加努力的学习。

PSP时间统计:

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

参考资料

结对编程练习
中缀转后缀
前缀、中缀、后缀表达式




























以上是关于20172320 结对编程项目-四则运算 第二周 阶段总结的主要内容,如果未能解决你的问题,请参考以下文章

20175325 第二周结对编程项目 四则运算

20165330 结对编程项目-四则运算 第二周

20165202 结对编程项目-四则运算 第二周

20172316 结对编程-四则运算 第二周 阶段总结

20175311胡济栋 2018-2019-2《Java程序设计》结对编程项目-四则运算 第二周 阶段性总结

20172319 结对编程练习_四则运算第二周阶段性总结