20165301 Pair Programming Project - Four Arithmetic (Week 2)

Pair Programming Project - Four Algorithms (Week 2)

demand analysis

  • Implement a command line program that requires:

  • Automatically generate four arithmetic problems in primary school (addition, subtraction, multiplication, division)
  • Integers are supported
  • Support for multiple operators (such as generating questions containing 100 operators)
  • True Score
  • Statistical accuracy rate
    Please enter the number of questions to be generated: <input 6>
  • As follows

题目1:
3 + 4 = <输入7>
正确!

题目2:
5 ÷ 8 = <输入5/6>
错误,正确答案为:5/8

题目3:
2/3 - 1/5 = <输入7/15>
正确!

题目4:
1/6 * 3/7 = <输入3/42>
正确!

题目5:
10 - 5 * 4 = <输入20>
错误,正确答案为:-20

题目6:
(1/3 + 1/2) * 11/20 = <输入55/120>
错误,正确答案为:11/24

完成6道题目,正确率为50%

Design ideas

  • Specify the number of generated questions and the number of operators in the form of command line parameters
  • deduplication

Key code explanation in the implementation process

  • Conditional statements for addition, subtraction, multiplication and division
char z =op.charAt(0);
     if(z=='+')
     System.out.printf("%f",x+y);
     else if(z=='-')
     System.out.printf("%f",x-y);
     else if(z=='*')
     System.out.printf("%f",x*y);
     else if(z=='/'){
     if(y==0){
     System.out.println("you can not do that");
     }
     else{
     System.out.printf("%f",x/y);

run screenshot

code link

code analysis

  • First write a loop to count the number of generated expressions for (int i = 0; i < number; i++)
  • Determine the type of operation, use if-else if-else statement, if it is '+', execute add(a, b) If the input data is equal to the correct result, output right
  • If the operation type is "-", execute minus(op1, op2), if the input data is equal to the correct result, output right
  • If the operation type is "*", execute times(op1, op2)
  • Div(op1,op2) is executed if the operation type is "*"
  • Finally, the ratio of the number of right to the input number is counted, and right/number is used to obtain the correct rate output.

Pair Summary (evaluation of team members)

  • This experiment is a rare experience for me. My personal programming ability is average. After passing the customs, I have discussed with my teammates 20165302 , flipped through the textbook, browsed the website to find ideas, and finally successfully completed this experiment. In the experiment, my teammates often took the initiative to ask me to discuss problems, which made me gradually let go of my laziness and start to be proactive. This is a huge advantage of group study for me.

pair study photo

Guess you like

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