paired second assignment

1. Topic selection and requirements

  Software Engineering (2018) Pair Programming Second Assignment

  For this homework, I first read the homework requirements with my teammates, and researched these two programming questions, and finally agreed that the first question is more suitable for us. The following are the relevant requirements for the automatic generation program of four arithmetic operations in elementary school:

  • Can automatically generate four arithmetic practice questions
  • The number of questions can be customized
  • User can choose operator
  • The maximum number set by the user (such as within ten, within one hundred, etc.)
  • The user chooses whether there are parentheses and whether there are decimals
  • The user selects the output method (such as output to a file, printer, etc.)
  • It is best to provide a graphical user interface (choose according to your own ability, mainly to complete the above functions)

2. Pairing partners

Teammate blog address: Liang Heng

I am the driver in this assignment and the following are my responsibilities:

  • Able to complete all the code work, the program basically realizes all the required functions, and upload the code to coding.net or GitHub code hosting system.
  • Be able to give an objective evaluation of the role played by the navigator in this programming work, and complete a summary of more than 500 words.

    3. Main code analysis

    Code address: Automatic generation program of four arithmetic operations in primary school

Program flow chart:

1. Variable Definition

        int title_number=0;//题目数量
        int[] operator={1,1,1,1};//加减乘除四个运算符选择
        int maxnum=100;//设置最大数
        int has_bracket=0;//选择是否有括号
        int has_decimal=0;//是否有小数
        int print_way=0;//选择输出方式

2. User requests input processing

  Here I explain with or without parentheses , other processing is similar.

        System.out.println("请选择是否有括号:");
        System.out.println("1.有   2.没有");
        while(1==1)
        {
            has_bracket=in.nextInt();
            if(has_bracket==1)
            {
                break;
            }   
            else if(has_bracket==2)
            {
                has_bracket=0;
                break;
            }
            else
                System.out.println("输入错误,请重新输入:");
        }

3. Formula output

I divided the formula output into the following four cases:

  • No parentheses and no decimals
  • without parentheses and with decimals
  • with parentheses and no decimals
  • With parentheses and decimals
    Among them, the case with parentheses and decimals is the most complicated, so I will use this situation as an example to explain my specific implementation process.
/*相关函数说明
*float get_random_float(int maxmun) 随机输出一个小于maxmun的浮点数
*int get_random_int(int minmun,int maxmun) 随机输出一个介于minmun和maxmun的正整数
*char get_operator(int[] operator)根据加减乘除运算符数组随机输出一个运算符
*/

int num=get_random_int(2,6);//算式中一共包含的数字总数
int flag=0;//标记括号是否已经输出
int bracket=0;//标记左括号输出概率
int bracket_you=0;//标记右括号输出概率
int decimal=0;//标记小数输出概率
int pre=0;//标记当前应输出数字,还是运算符

while(num!=0)
{
    if(pre==0)
    {
        if(num!=1&&flag==0)
        {
            bracket=get_random_int(0,10);
            if(bracket>8)
            {
                System.out.print("(");
                flag=num;
            }
        }
        decimal=get_random_int(0,4);
        if(decimal<3)
            System.out.print(get_random_int(1,maxnum));
        else
            System.out.printf("%.2f",get_random_float(maxnum));
        pre=1;
        num--;
    }
    else
    {
        if(bracket>8&&(flag-num)!=1&&flag!=1000)
        {
            bracket_you=get_random_int(0,10);
            if(bracket_you<6)
            {
                System.out.print(")");
                flag=1000;
            }
        }
        System.out.print(get_operator(operator));
        pre=0;
    }
}
//如果数字已经输出完毕,判断右括号是否已经输出过
if(flag!=1000&&bracket>8)
    System.out.print(")");
System.out.print("="+"\n");

4. Program running results

1) output to the screen

2) output to file

5. Program Overview

  This program has realized all the requirements of the question, and can automatically generate the four arithmetic practice questions of the specified requirements, but the fly in the ointment is that there is no graphical interface.

4. Navigator job evaluation

  In this pairing program, I acted as the pilot, and my partner Liang Heng acted as the navigator. Through the example of automatic generation of programs based on four arithmetic operations in elementary school, I think pair programming has both advantages and disadvantages. The advantage is that we are also reviewing when programming, which can reduce the probability of our program errors, improve code quality, and discuss and cooperate with each other, which will analyze problems more thoroughly and have better problem solving ability. For example, in the example of the automatic generation program of four arithmetic operations in primary school, I did not compare the size of the two input parameters in the function of randomly generating integers, ignoring the case of zero, but Liang Heng was just doing this function I found this small problem in the code test of , and I corrected it in time. If this is me programming alone, ignore this small problem, and the program still has bugs, I may spend a long time looking for this bug, and I may not be able to find it for a long time, and I have to go Ask others. So when pair programming, we can save some time to find bugs, and the key functions still need to be tested again. And when pair programming, I feel that the efficiency of programming is higher when two people are together than when one person is programming, and the teammates are more passionate, so he motivates me in this regard, the programming efficiency is higher, the rhythm is faster, and there is no one Waste more time on small issues. But everything has two sides, and pair programming is no exception. It also has some problems. For us, I think there is a timing issue. Pair programming needs to find when we have time. In addition to the normal class time, I also signed up for the postgraduate entrance examination class on campus. He signed up for the postgraduate entrance examination class outside the school. We also have our own affairs. It is not easy to find a time when two people are free to program. Fortunately, we are roommates, so we quickly passed the running-in stage and used the evening time to discuss and program together. In general, this pair programming is still fresh to us. I believe that we will have a better understanding of pair programming in the future. Come on!

A final photo is attached:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324579363&siteId=291194637