Second pairing assignment in software engineering

Software engineering second group assignment

1. Subject requirements

When we first started the class, we introduced an example of an automatic generation program of four arithmetic operations in elementary school. Please implement it and require:

  • 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. Team configuration

Driver: Guo Jing

  • Able to complete all code work, the program basically realizes all 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 (5 points)

Pilot: Chang Yuan

  • It can assist the driver to complete all the code work, and select appropriate coverage standards for key functions to design test cases, and write code for unit automatic testing
  • Ability to evaluate the driver's current work based on the code checklist from the previous work
  • Able to complete a summary of more than 500 words on this work
  • image_1cb76rkem8601irg1r6k1lgh4qd2a.png-1860.3kB

3. Program realization

Before writing the program, the two of us did a little analysis of the requirements of the topic to determine what functions we want to make and whether we need to add additional functions (maybe a simple requirements analysis). The following are our thoughts:
1. The question should not be too difficult, the target is primary school, so the question should be controlled within 3 yuan
2. The question does not require us to calculate the result of the formula, but considering the needs of users, we decided to add
3. The decimal part can be controlled to one place after the decimal point

Then there is programming. In terms of programming, I selectively pick out some parts that I think are more important to introduce.

  1.         int kind[]=new int [4];
            System.out.println("请输入运算符种类 0.+   1.-   2.x    3.÷    以5键结束");
            for(i=0;i<4;i++)
            {
                choose=scan3.nextInt();
                if(choose==5) {
                    break;
                }
                else {
                    kind[i]=choose;
                    num++;
                }
            }

Here I use a kind array to store the labels of the four operators, and record the length of the array, and then use this to implement the function of selecting operators.

  1.             double a=(double)(Math.random()*B);//随机生成一个小数
                double b=(double)(Math.random()*B);//随机生成一个小数
                double c=(double)(Math.random()*B);//随机生成一个小数
                int d=(int)(Math.random()*num);
                int flag3=kind[d];//随机生成一个0-3的整数,0表示加法,1表示减法,2表示乘法,3表示除法

This is the 5 random number generation part of the positive part. a, b, c are used for columnar, d and flag are used to control the desired operator based on user input.

  1.         if(flag==0&&flag0==0)//无括号加法
        {
            d1=a+b;
            System.out.print(a+"+"+b+"=       ");
            daan[i]=d1;
        }
         if(flag==0&&flag0==1)//有括号加法
        {
            d1=a+b+c;
            System.out.print("("+a+"+"+b+")"+"+"+c+"=       ");
            daan[i]=d1;
    
        }
    
        if(flag==1&&flag0==0)//无括号减法
        {
            d1=a-b;
            System.out.print(a+"-"+b+"=       ");
            daan[i]=d1;
        }
        if(flag==1&&flag0==1)//无括号减法
        {
            d1=a-(b-c);
            System.out.print(a+"-"+"("+b+"-"+c+")"+"=       ");
            daan[i]=d1;
    
        }   
        if(flag==2&&flag0==0)//无括号乘法
        {
            d1=a*b;
            System.out.print(a+"*"+b+"=       ");
            daan[i]=d1;
    
        }
        if(flag==2&&flag0==1)//无括号乘法
        {
            d1=a*b*c;
            System.out.print("("+a+"*"+b+")"+"*"+c+"=       ");
            daan[i]=d1;
    
        }
    
        if(flag==3)//除法
        {
            d1=a/b;
            System.out.print(a+"÷"+b+"=       ");
            daan[i]=d1;
        }
    
        if((i+1)%3==0)
        {
            System.out.println();
        }
    
    }
    When flag is 0, there are parentheses, and when it is 1, there are no parentheses. According to different flag, flag0 value, the required formula is randomly output.
    The above part is the code of the positive part. The code of the decimal part is roughly the same as that of the positive part, but the variable type and output are somewhat different, so I will not describe it in detail here.

4. Sample test

1. Test Example 1: Overall Run Test

image_1cb73uo5i3hq34n3b81et55n79.png-12.5kB


2. Test example 2:
Integer question test 1, choose the number of questions within 20, within 10, with parentheses, and the operator type is + - ÷

image_1cb74br8c154sfqf170nd1m6l2m.png-31.4kB


Integer question test 2, choose the number of questions within 10,8, no parentheses, the operator type is - x

image_1cb74g0p4l6a4vu1dvtfhrc8313.png-19.8kB


3. Test example 3:
Decimal question test 1, select the number of questions within 7,9, no parentheses, the operator type is + x

image_1cb74m95r1h0l1bj7o4g1i8i36e1g.png-24.3kB


Decimal question test 2, the number of selected questions is less than 6,40, with parentheses, the operator type is -

image_1cb74s4541t1jdbt15f411frutc1t.png-22.3kB


5. Summary

Wow, it's really a difficult question for a novice like me in actual programming. The topics I did in the past were all related to the knowledge points given by the teacher, and most of the programming time I was writing general algorithms, and I didn't think about specific problems in many cases. It's no wonder that every time the course design is kakaka, my own comprehensive ability still needs to be greatly improved! If it wasn't for pair programming, with a teammate, it might be a question if I could do it by myself in just a few days.

Having a teammate is really important, especially when doing questions. For myself, sometimes when I think about a certain problem, I fall into my own misunderstanding, and I always get stuck, and one card is stuck for a long time. Maybe it's a lack of skills and knowledge. If I enter this state, I will become a little impetuous, which will lead to more confusion in my heart, and I will enter an infinite loop, unable to get out, and consume a lot of time and energy. After I have a pair of teammates this time, the two sides will communicate. In this way, sometimes my problems can be solved very easily in his thinking. For example, in the program, I am very concerned about how to control the decimal places of random output. Confused, I have been looking for it, and I can control the decimal to one decimal place in the random part. However, I have been searching for a long time, but I have not found a way, and I am at a loss. At this time, my teammates told me, why don't you switch it when the final output is done? The real value does not change, just output one decimal place when printing, after all, it is a question! In this way, I had an idea at once, and after a few waves, I passed it smoothly. In fact, it is a very simple operation, but for me, sometimes it is such a small misunderstanding that it bothers me very much. Not only that, when analyzing the needs of this question, my teammates and my ideas often complement me. I didn’t expect that he would bring it up and discuss whether it was necessary, such as the link of outputting results. If it wasn’t for him, I might Abandoned this step, his ideas complement my deficiencies!

In addition, the shortcomings of my program still have many shortcomings, such as the code is verbose, the variable definition is not standardized and so on. At that time, it was still based on the premise of making this topic, so the control of details was still a lot worse, not so fine. When writing, you can feel that there are many parts of the code that can be simplified or written in a more efficient way. but. . The two of us are not very strong. At some point, if we can't think of a good function or way to write it, the two of us still decide to use a stupid method, which may be cumbersome, but can solve the problem in a way that can accomplish the goal. I hope that I can improve my programming level in the future, and the skills of the two can be more efficient.

In general, this pair programming still gave me a lot of freshness, because in the past, everyone did their own thing. In terms of pairing, I still have a deep impression on me. This is just a pairing of two people. If the number of people increases, the quality of the program will become very high, especially when multiple people review it again. Test the quality of the code. This experiment was really a very rewarding experience for me!


6. Appendix

Code link: https://coding.net/u/q842774912/p/Groupwork_2/git/blob/master/Lab2.java?public=true

Guess you like

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