2017-2018-2 20172302 "Java Programming" course pair programming Exercises _ arithmetic

Source: Internet
Author: User
Tags arithmetic

Tag: Val inf includes return rand www. ODI an infix expression

1. Pairs of objects

20,172,308 weeks Yajie

2. This week's content requirements analysis
    • (1). Automatic generation of topics
    • can be used independently (able to write the function of the test class to create a separate problem)
      can generate different levels of topics, similar to:
      Level 1 Topics: 2 + 5 =, 10-5 = Two numbers, the title of an operator

    • (2). Problem calculation (question)
      Can be used independently, to achieve the infix expression to the suffix expression and calculation; Determine the user's answer right and wrong, and output the correct results

    • (3). True score Support
    • Can be used independently to achieve the calculation of fractional formulas

    • (4). Topic Go Heavy (expand demand, add sub-item)
    • Can be used independently, to achieve the de-weight of the auto-generated expression: The following if generated: 2 + 5 = & 5 + 2 = for the same topic

Design analysis
    • 1. Automatic generation of the topic: the difficulty of the topic here I was defined by the number of operators, according to the operator and then produce the Operation Fugai number (here is not the case of the photo fraction), and then use the loop to produce, and then output as a string.

    • 2. infix suffix: This code to write the two of us is the exchange of independent completion, I use the operator priority table to generate a two-dimensional array, according to the index value to determine the priority, determine whether the operator is in the stack or out of the stack, for the digital output directly, Then the last operator in the stack is then output one by one to complete the output of the suffix expression.

    • 3. Suffix evaluation: Here is written by a method: From left to right scan the suffix expression, encountered the operand into the stack, encountered the operator will pop up the top of the stack of two elements, the results are calculated and then pressed into the stack, the last stack of the remaining element is the final answer

Design UML class diagram (emphasis!!!) )

The design of UML class diagram is shown below:

Problems encountered and workaround code presentation
    • Automatically generate the topic:
package arithmetic;import java.util.Random;import java.util.ArrayList;public class Questions{    ArrayList<Object> array = new ArrayList<Object>();    Random generator = new Random();    char [] newchar = {'+','-','*','/'};    protected int number;    int NUM;    public Questions()    {        number = 0 ;    }        public Object getQuestion(int num) {            int num1 = num;            while (num > 0) {                int figure = (int) generator.nextInt(9) + 1;                array.add(figure);                number = (int) (Math.random() * 4);                array.add(newchar[number]);                num--;            }            String obj = "";            while (num < 2*num1) {                obj += array.get(num);                num++;            }            int other = (int) generator.nextInt(9)+1;            array.add(other);            obj+=other+"=";            return obj;        }    }
    • infix turn suffix:
Package Arithmetic;import Java.util.stack;public class test{private int number,num1,num2;    private int value1,value2;    private int index=0; Private int[][] Array = {{0,0,0,0,0}, {0,1,1,-1,-1}, {0,1,1,    -1,-1}, {0,1,1,1,1}, {0,1,1,1,1}};      Public String obj= "2+1-2*2-2/1=";    Stack stack = new stack ();        Public test () {num1=0;        num2=0;        value1=0;    value2=0;        public string Getanswer () {String result = "";            while (Index<obj.length ()-1) {char x = Obj.charat (index);            if (x>= ' 0 ' &&x<= ' 9 ') result + = x+ ""; else {switch (x) {case ' + ': Number =                        1;                    Break                   Case '-': number=2;     Break                        Case ' * ': number = 3;                    Break                        Case '/': number=4;                Break                    } if (Stack.empty ()) {num1 = number;                Number = 0;                        } else {num2 = number;            number=0;                    } if (array[num1][num2]<=0) {stack.push (x);                Value1 +=1;                    } else {result+=stack.pop ();                    Stack.push (x);                    Value1 +=1;                Value2 +=1;            }} index++;        } for (int y =0;y<value1-value2;y++) result + = Stack.pop ();    return result; }}
    • Suffix expression evaluation:



3.PSP Analysis
PSP2.1 Personal software Process Stages Estimated time-consuming (minutes)
Planning Plan 60
Estimate Estimate how long this task will take 3
Development Development 2000 3000
Analysis Demand analysis (including learning new technologies) 350
Coding Standard Code specification (to develop appropriate specifications for current development) 60
Design UML Design Project UML class diagram 60
Coding Specific code 1500
Code Review Code review 30
Test tests (Self-test, modify code, commit changes) 300
Size Measurement calculation effort (actual time) 2 2
Postmortem & Process Improvement Plan Summarize afterwards and propose process improvement plan 30
Total 4395

2017-2018-2 20172302 "Java Programming" course pair programming Exercises _ arithmetic

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.