20172303 2017-2018-2 "Program Design and Data Structure" Pair Programming Project - Four Operations

20172303 2017-2018-2 "Program Design and Data Structure" Pair Programming Project - Four Operations

paired object

  • Name: Zhang Haoran
  • Student ID: 20172322
  • Blog address for the first week:
  • Take on the role:
    • Early stage: determine the number of classes and the basic writing of each class
      • Pilot: Fan Wenqi
      • Operator; Zhang Haoran
      • Explanation: In the early stage, I was mainly to determine what functions each class has, and what methods there are in it. Zhang Haoran is responsible for typing out the general picture in IDEA first. When there is a problem, I will check and he will do other things. (In fact, in the early stage, he did a lot of work, and it took a long time to write each class)
    • Mid-term: class modification and optimization (no obvious role difference)
      • Explanation: At this stage, the role is not very obvious. The two people evenly distribute all the classes to find the mistakes. If they find it, they will solve it themselves. If they can't solve it, they will discuss it together.
    • Post: try adding parentheses
      • Pilot: Zhang Haoran
      • Operator: Fan Wenqi
      • Explanation: Zhang Haoran thought of the idea of ​​adding parentheses in infix to suffix and adding parentheses when generating questions, and then I was responsible for implementing his ideas with specific codes.

demand analysis

  • Questions can be automatically generated, and the difficulty and number of questions can be defined by the user
  • The questions support integers, true fractions and four arithmetic operations of addition, subtraction, multiplication and division
  • It can judge whether the user's answer is correct and output the correct answer, and finally calculate the correct rate of the user
  • Expansion requirements:
    • topic de-duplication
    • Support multiple languages, the language type can be selected by the user
    • The generated questions and their correctness and errors can be saved in a notepad file

Design ideas

1. Generate random rational numbers

  • An operand class is designed so that it can randomly generate a rational number, either an integer or a true fraction.

2. Generate the topic

3. Calculation problems

4. Test class

  • Design a test class that allows users to input the difficulty and number of questions, judge true and false, and calculate the rate.

Five, UML diagram

Relevant process and explanation

Infix to suffix method implementation

import java.util.*;

public class InfixToSuffix
{
    private Stack<String> stack;
    private List<String> list;

    private String message, Message = "";


    public InfixToSuffix() {
        stack = new Stack<String>();   //  Store operator
        list = new ArrayList<String>();   //  Store operation number and operator
    }

    public void conversion(String expr) {
        String token;
        StringTokenizer tokenizer = new StringTokenizer(expr);

        while (tokenizer.hasMoreTokens()) {
            //  If tokenizer has the next value, loop and assign value.
            token = tokenizer.nextToken();

            if (token.equals("(")) {
                //  If the value of the token is the left parenthesis, then the stack
                stack.push(token);
            }else if (token.equals("+") || token.equals("-")) {
                //  If the value of token is "+" or "-", once again determine whether the stack is empty.
                if (!stack.empty()){
                    //  If the stack is not empty, judge what is the top element of the stack
                    if (stack.peek().equals("(")) {
                        //  If the top of the stack is "(", the operator enters the stack
                        stack.push(token);
                    }else{
                        //  Otherwise, remove the stack top elements first, add them to the list,
                        //  and then stack the operators into the stack.
                        list.add(stack.pop());
                        stack.push(token);
                    }
                }else {
                    //  Otherwise the operator enters the stack
                    stack.push(token);
                }
            }else if (token.equals("*") || token.equals("÷")){
                //  If the value of token is "*" or "÷", it again determines whether the stack is empty.
                if (!stack.empty()) {
                    //  If the stack is not empty, judge what is the top element of the stack
                    if (stack.peek().equals("*") || stack.peek().equals("÷")) {
                        //  If the top of the stack is "*" or "÷", remove the stack top elements first,
                        //  add them to the list, and then stack the operators into the stack.
                        list.add(stack.pop());
                        stack.push(token);
                    }else {
                        //  In addition, the operator directly enters the stack.
                        stack.push(token);
                    }
                }else {
                    //  If the stack is empty, the operator goes directly to the stack
                    stack.push(token);
                }
            } else if (token.equals(")")) {
                //  If encounter "), starts to circulate
                while (true) {
                    //  Remove the top element of the stack and assign it to A
                    String A = stack.pop();
                    if (!A.equals("(")) {
                        //  If A is not "(", it is added to the list
                        list.add(A);
                    } else {
                        //  If A is "(", exit the loop
                        break;
                    }
                }
            }else {
                //  If it is an arithmetic number, enter the list
                list.add(token);
            }
        }
        while (!stack.empty()) {
            //  Remove elements from the stack and add them to the list until the stack is empty.
            list.add(stack.pop());
        }
        ListIterator<String> li = list.listIterator();
        while (li.hasNext()) {
            Message += li.next() + " ";
            //  The elements in iterator are taken out in turn, and spaces are used as separators.
            li.remove();
        }
        message = Message;
    }

    public String getMessage() {
        return message;
    }
}

The key point of this part is StringTokenizer类that it was given to us by Senior Zhang Xusheng during a certain evening self-study.

Its specific methods are:

Screenshot of the running process

code hosting

Difficulties encountered and solutions

  • Question 1: In the test class, if the number of questions is input "0", there will still be a question, and if the difficulty of the question is input "0", an error will be prompted.
  • Solution: Modify the test class, no matter where you enter "0", an error will be prompted.

    int j = 0;
            System.out.print("请输入要生成的题目数:" );
            count = number.nextInt();
            while (count == 0)
            {
                System.out.println("错误,请输入有效数字!(最小为1,理论无上限)");
                System.out.print("请输入要生成的题目数:");
                count = number.nextInt();
            }
            System.out.print("请输入生成题目的级别(每增加一级多一个运算符,最低为一级):");
            level = number.nextInt();
            while (level == 0)
            {
                System.out.println("错误,请输入有效数字!(最小为1,理论无上限)");
                System.out.print("请输入生成题目的级别(每增加一级多一个运算符,最低为一级):");
                level = number.nextInt();
            }
  • Problem 2: Multiple identical operands and operators are output when generating questions
  • Solution: Using single-step debugging, it is found that a certain "operand + operator" is added in one step.
  • Problem 3: After adding parentheses, the generated question level does not match the actual level (level equals the number of symbols)
  • Solution: After many revisions without success, I asked Yu Xinyue, but the way they set levels is different from ours (they set the first level as addition and subtraction, the second level as multiplication and division, and the third level as addition, subtraction, multiplication and division) So it didn't help us solve the problem, we will solve this problem as soon as possible in the next week.

Comment on paired friends

  • Zhang Haoran really put a lot of effort into this pairing process. He basically completed the main body of the code. Originally, we were two people who did not need parentheses, but he agreed after my argument. Even if the content of Chapter 10 remains unfinished.
  • The disadvantage is that you don't know how to use tools. When the code is wrong, you still think about it step by step. I didn't think of using the DeBug function _(:з"∠)_

Team work together

In fact, in the early and mid-term, we basically do it separately, or one person finishes doing it for another person, but the part with brackets is the most focused discussion.
When infix to suffix, I almost rewrote the code in order to add parentheses to the draft many times.
When the question was generated, my original idea was to randomly generate the left and right parentheses as operators, but if the left parenthesis must be in front of the right parenthesis and there are at least two operands and operators within the parentheses, it will be very trouble. And Zhang Haoran put forward another idea, which is to set a random number after the question generation operator to determine whether to add parentheses. It is much simpler to implement the above functions. After the last generated question can generate parentheses, it is really very successful. feel.

However, there are still many problems in our generation of parentheses. For example, the existence of parentheses makes the level inconsistent with reality, and now we can only put two operands and operators in parentheses. We couldn't solve it this week due to time and personal ability issues, but will definitely get it done the next week.

PSP

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

References

Guess you like

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