20172324 Pair programming project - four arithmetic operations first week phase summary

20172324 Pair programming project - four arithmetic operations first week phase summary

paired object

  • Student ID 20172321
  • Name Wu Hengyi
  • Partner's first week blog: Xiao Wu's blog
  • Take on the role:
  • Driver: Wu Hengyi
  • Driver: Zeng Cheng

(Everyone is responsible for things will always be done slowly

demand analysis

Functional requirements

<1> It can automatically generate four arithmetic questions for elementary school according to different difficulty requirements

  • Can be used independently (can realize the function of writing test classes to generate questions independently)
  • Different levels of questions can be generated. The first-level question has only one operator, and so on. The highest level is the fifth level.

<2> Item operation

  • Can be used independently
  • Fractional operations are possible (true fractions)
  • Convert an infix expression to a postfix expression and output the conversion result and answer
  • Determine whether the user's answer is right or wrong, and output the correct result
  • Calculate the correct rate

<3> Topic de-duplication (expansion requirements, extra points)

  • Can be used independently
needs understanding
  1. The class of randomly generated questions must satisfy the difficulty and the number of questions requested by customers.
  2. You need to create a class to convert infix expressions into postfix expressions
  3. A class that evaluates the result of a postfix expression
  4. Classes for judging correct and incorrect questions
Subsequent expansion

I have no idea for the time being, but if there is one, it will definitely be added. Is it possible to do this by chance...

Design ideas

  1. How can we randomly output the questions, especially, we can output the question level and the number of questions according to customer needs? (Store the operator symbols in the array, use random to randomly select operators and generate numbers from 1 to 100, the first order can be directly connected with +, and the second order and above need to use a for loop. As for the difficulty of the customer Select, use switch statement, the customer enters a few levels of difficulty to reach the case of that difficulty.)
  2. Convert infix to suffix? (Using stack, first the stack is empty, scan the original formula from left to right, if the operand is encountered, output directly, and output a space as the separator between the two operands, if the operator is encountered, compared with the top of the stack, If it is higher than the top level of the stack, it will be pushed into the stack, otherwise it will exit the top element of the stack and output, and then output a space as a separator. And before pushing into the stack, create a two-dimensional array to define the priority of the operator)
  3. Calculate postfix expressions? (Set up an operand stack, start the stack empty, scan from the left, push the stack with the operand, if the AND operator, exit two elements from the stack, first exit on the right, then exit on the left, operation Back on the stack, until the last element is the result after scanning)
  4. Judgment of right and wrong and correct rate (if right or wrong, first calculate the correct result in the program but not output, and then compare with the result input by the customer, consistent output true, inconsistent output false. If the correct rate is to divide the correct number of questions by total number of questions)

The uml class diagram is shown in the following figure

Difficulties encountered and solutions

  • Problem 1 and the solution: I went astray at first, I directly used the main method to generate the title without creating a class. The reason is because I found that some operations cannot be performed without the main method, such as switch, for and the like, there will be error prompts. In the end, it was fortunate that Wang Wenbin gave guidance and taught me how to create a class.
  • Problem 2 and no solution: Now I have encountered a big, big, big problem... There is no problem with debug, it should be a logical error, but I have not thought of a solution. Below is the code

Formula subclasses that generate calculations

import java.util.*;
import java.util.Random;
import java.util.Scanner;

public class levelclass {
    public levelclass(){
        char[] operator = new char[]{'+', '-', '*', '÷'};
        Random random = new Random();
        Scanner scan = new Scanner(System.in);
        int num;
        int level;
        System.out.println("该程序只能计算一到五个操作符的算式。");
        System.out.println("输入你需要测试的算式等级:");
        level = scan.nextInt();
        System.out.println("输入你需要的式子数量:");
        num = scan.nextInt();
        switch (level)
        {
//一级算式
            case 1:


                ArrayList<String> expression1 = new ArrayList<String>();
                for (int i = 0; i < num; i++) {
                    int n = random.nextInt(1) + 1; //1个运算符
                    int[] number = new int[n + 1];
                    String ex = new String();

                    for (int j = 0; j <= n; j++) {
                        number[j] = random.nextInt(100) + 1; //2个数字
                    }
                    for (int j = 0; j < n; j++) {
                        int s = random.nextInt(4);//随机选择某个运算符

                        ex += String.valueOf(number[j]) + String.valueOf(operator[s]);
                        if (s == 3) {
                            number[j + 1] = decide(number[j], number[j + 1]);
                        }
                    }
                    ex += String.valueOf(number[n]);
                    ex += "=";
                    expression1.add(ex);


                }
                for(int ii = 0; ii < expression1.size() ; ii++)
                {
                    System.out.print(expression1.get(ii) + "\n");
                }
//                System.out.println(expression1);
                break;
//二级算式
            case 2:
                ArrayList<String> expression2 = new ArrayList<String>();
                for (int i = 0; i < num; i++) {
                    int n = random.nextInt(1) + 2; //2个运算符
                    int[] number = new int[n + 1];
                    String ex = new String();

                    for (int j = 0; j <= n; j++) {
                        number[j] = random.nextInt(100) + 1; //3个数字
                    }
                    for (int j = 0; j < n; j++) {
                        int s = random.nextInt(4);//随机选择某个运算符

                        ex += String.valueOf(number[j]) + String.valueOf(operator[s]);
                        if (s == 3) {
                            number[j + 1] = decide(number[j], number[j + 1]);
                        }
                    }
                    ex += String.valueOf(number[n]);
                    ex += "=";
                    expression2.add(ex);

                }
                for(int ii = 0; ii < expression2.size() ; ii++)
                {
                    System.out.print(expression2.get(ii) + "\n");
                }
                break;
//三级算式
            case 3:
                ArrayList<String> expression3 = new ArrayList<String>();
                for (int i = 0; i < num; i++) {
                    int n = random.nextInt(1) + 3; //3个运算符
                    int[] number = new int[n + 1];
                    String ex = new String();

                    for (int j = 0; j <= n; j++) {
                        number[j] = random.nextInt(100) + 1; //4个数字
                    }
                    for (int j = 0; j < n; j++) {
                        int s = random.nextInt(4);//随机选择某个运算符

                        ex += String.valueOf(number[j]) + String.valueOf(operator[s]);
                        if (s == 3) {
                            number[j + 1] = decide(number[j], number[j + 1]);
                        }
                    }
                    ex += String.valueOf(number[n]);
                    ex += "=";
                    expression3.add(ex);

                }
                for(int ii = 0; ii < expression3.size() ; ii++)
                {
                    System.out.print(expression3.get(ii) + "\n");
                }
//四级算式
            case 4:
                ArrayList<String> expression4 = new ArrayList<String>();
                for (int i = 0; i < num; i++) {
                    int n = random.nextInt(1) + 4; //4个运算符
                    int[] number = new int[n + 1];
                    String ex = new String();

                    for (int j = 0; j <= n; j++) {
                        number[j] = random.nextInt(100) + 1; //5个数字
                    }
                    for (int j = 0; j < n; j++) {
                        int s = random.nextInt(4);//随机选择某个运算符

                        ex += String.valueOf(number[j]) + String.valueOf(operator[s]);
                        if (s == 3) {
                            number[j + 1] = decide(number[j], number[j + 1]);
                        }
                    }
                    ex += String.valueOf(number[n]);
                    ex += "=";
                    expression4.add(ex);

                }
                for(int ii = 0; ii < expression4.size() ; ii++)
                {
                    System.out.print(expression4.get(ii) + "\n");
                }
//五级算式
            case 5:
                ArrayList<String> expression5 = new ArrayList<String>();
                for (int i = 0; i < num; i++) {
                    int n = random.nextInt(1) + 5; //5个运算符
                    int[] number = new int[n + 1];
                    String ex = new String();

                    for (int j = 0; j <= n; j++) {
                        number[j] = random.nextInt(100) + 1; //6个数字
                    }
                    for (int j = 0; j < n; j++) {
                        int s = random.nextInt(4);//随机选择某个运算符

                        ex += String.valueOf(number[j]) + String.valueOf(operator[s]);
                        if (s == 3) {
                            number[j + 1] = decide(number[j], number[j + 1]);
                        }
                    }
                    ex += String.valueOf(number[n]);
                    ex += "=";
                    expression5.add(ex);

                }
                for(int ii = 0; ii < expression5.size() ; ii++)
                {
                    System.out.print(expression5.get(ii) + "\n");
                }

        }

    }

    private static int decide(int x,int y){//通过递归实现整除
        Random random=new Random();
        if(x%y!=0){
            y=random.nextInt(100)+1;
            return decide(x,y);
        }
        else{
            return y;
        }
    }

    public void produce(){


    }
}

class implementation

public class test {
    public static void main(String[] args) {
        levelclass a = new levelclass();
        a.produce();
    }
}

The problem is that when the customer enters the test level 3, the questions that come out will be three times the questions that the customer needs to enter, as shown in the figure

When the client enters a test level 4, the questions that come out will be twice as many as the client needs to enter, as shown in the figure

All other cases are correct. I debugged and found that in case3 and case4, the program will loop 3 times and twice respectively. But the code in these two cases is the same as the code in case 1, 2, and 5. Wu Hengyi and I thought about it for a long time and didn't know why.

Achievements so far

  • The first-order questions can be judged right and wrong and the correct rate, but the second-order and above are temporarily unavailable
  • You can randomly generate questions and choose the difficulty and number of questions

PSP time statistics:

PSP2.1 Personal Software Process Stages Estimated time (minutes) Actual time (minutes)
Planning plan 50
Estimate Estimate how long this task will take 60
Development develop 600
Analysis Requirements analysis (including learning new technologies) 150
Coding Standard Code Specifications (to develop appropriate specifications for current development) 45
Design UML Design project UML class diagram 20
Coding specific code 180
Code Review code review 60
Test Testing (self-testing, modifying code, committing changes) 100
Size Measurement Computational workload (actual time) 30
Postmortem & Process Improvement Plan Post-event summary, and propose a process improvement plan 20
total 1315

Guess you like

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