2017-2018-2 20172310 "Java Programming" course pair programming Exercises _ arithmetic _ first week knot to small partners:
Requirements analysis (describe your own understanding of requirements and the likelihood of subsequent expansions)
-
- can automatically generate a certain amount of topics according to the needs of users, and the level of the topic can be changed.
such as: 2 + 5 =
2+53 =
(2+5)3 =
(2+5) *3/2=
These are the problems of different grades. (The number of operands and operators is different, the advanced topics contain different operational levels)
- Support Brackets
- can be used independently (able to write the function of the test class to create a separate problem)
-
- Problem calculation (problem), can be used independently
- Implement infix expression to postfix expression and calculate
- Judge the user's answer correctly and output the correct result
-
- Support True Score
- can be used independently
- Realization of the calculation of fractional formulas
-
- Subsequent extensions: Completion of the expression of the random parentheses, the topic to re-type.
Design ideas (output UML class diagram at the same time)
- When I thought about the first question, I was going to just create a class that would design three methods in this class to get three different levels of problems, but then I would have to keep creating the methods, and the methods needed to initialize different random objects. At this point, the teammate proposed that the requirements are randomly generated at different levels of the topic, it is too wasteful, and can not be based on the actual need to determine a number of operators and operands. This is also prone to errors.
This time I thought of the inheritance that I learned last week, since every method is necessary for operators and operands, then why not create a parent class and write it in the parent class, then we select the second method.
This is some key code at this stage
public class Expressions2 extends Issue { String num;// protected String Expression;// String mount; String ope;
//我现在需要一个随机数,来表示题目等级,然后随机确定题目的等级
Public String Getstage ()
{
num = GetRandomNumber ();
Expression = num + "";
Random stsge = new Random();int a = stsge.nextInt(4);for (int b =0 ;b <= a;b++){ ope = getOperator(); Expression += ope + " "; num = getRandomNumber(); Expression += num + " ";}return Expression;
}
}
2. infix expressions are converted to suffix expression expressions and the results are computed.
Stack is a new knowledge learned in the process of solving this problem.
Lists, pairs of columns, and stacks are linear data structures. The heap-looking stack is similar to a queue, except that the stack element enters and moves out of the stack at the same end of the stack, and finally
An element that goes into the stack is the first element to move out of the stack, like a stack of plates placed in a cupboard or a pile of hay in a barn. A stack is a linear structure that manages data in a last-in, first-out manner.
In accordance with the principle of the teacher explained the stack, I tidied up the infix expression into a suffix expression of the idea, for example:
+ (3-1)3+6/2, converting to suffix expression
1, encountered 9 output 9, this time the screen shows 9, the stack is empty
2, encountered the + number, at this time the stack empty, directly into the stack, this time the screen display 9, stack element only one + number
3, encountered the opening parenthesis, directly into the stack, at this time the screen display 9, the stack element is + (
4, encountered 3, output 3, this time the screen display 9 3, stack element is + (
5, encounter-number, the top element of the stack is (, into the stack, this time the screen displays 9 3, the stack element is + (-
6, encountered 1, Output 1, this time the screen display 9 3 1, the stack element is + (-
7, encountered), continue out of the stack until the top of the stack (and will (out of the stack but not output, and) not into the stack. The screen now displays 9 3 1-The stack element is +
8, encountered , at this time the top element of the stack is +, the priority is greater than the top element, into the stack, at this time, the screen display 9 3 1-, the stack element is +
9, encountered 3, output 3, this time the screen display 9 3 1-3, stack element is +
10, Encounter +, at this time the top element of the stack , the priority is greater than equal to +, out of the stack and output, after the top of the stack is +, the priority is still greater than or equal to +, out of the stack and output, at this time the stack empty, + into the stack
The screen now displays 9 3 1-3 +, the stack element is +
11, encountered 6, output 6. The screen now displays 9 3 1-3 * + 6, and the stack element is +
12, encountered/, priority is greater than the top of the stack element, into the stack, at this time the screen display 9 3 1-3 * + 6, stack element is +/
13, Encounter 2, Output 2, this screen display 9 3 1-3 * + 6 2
14, at this time all input read completed, the stack of elements sequentially out of the stack to empty, and finally, the screen display 9 3 1-3 * + 6 2/+
Current code (there may be some flaws, subsequent modifications will continue)
public class Transvertor {
private int num1, num2, value1, value2, number;
Private stack stack1 = new stack ();
Private String result1;
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 Transvertor () {num1 = 0;num2 = 0;value1 = 0;value2 = 0;result1= "";} public string Getanswer (string Expression) {StringTokenizer st = new StringTokenizer (Expression); St.hasmoretokens ()) {String A = St.nexttoken (); if (A.equals ("-") | | A.equals ("+") | | A.equals ("x") | | A.equals ("÷")) {switch (A) {case "+": Number = 1; Break Case "-": Number = 2; Break Case "X": Number = 3; Break Case "÷": Number = 4; Break } if (Stack1.empty ()) {Stack1.push (A); NUM1 = number; value1++; } else {num2 = number; if (Array[num1][num2] <= 0) {Stack1.push (A); Value1 + = 1; } else {result1 + = Stack1.pop () + ""; Stack1.push (A); }}} else reSULT1 + = A + "";} for (int y = 0; y < value1; y++) Result1 + = Stack1.pop () + ""; return RESULT1;
}
Public String GetResult ()
{
return RESULT1;
}
}
3. True score implementation at this stage there are only simple ideas, the code has not been written to complete. (?????)?
Class diagram
Comments:
- The fraction class is designed to produce a true fraction and can be used independently.
- The issue class produces a random operand and operator, which is the parent class of the expressions class, and expressions is used to generate an expression that contains a true fraction but does not contain parentheses at this stage.
- The Transvertor class is the key, including two methods, one to the infix expression to the suffix expression, and a suffix expression to calculate the result.
- The questions class is instantiated.
- The judgement class is used to test whether the user answers correctly and to count the correct number to calculate the correct rate
Make a comment on a pair of small partners
- Comments on teammates:
- The ability to write code is strong, the logic of the code is clear and simple.
- Flexibility is very strong yo ("the"), as in the infix expression to the suffix expression, we need to determine whether it is an operator or operand, the teacher gives the opinion is to use the ASCII character set to determine if it is within the range of 48-57, but we have to produce an expression when the score already exists, So to judge is more troublesome, so the team-mates wit to change a way of thinking-directly judge the operator. (。 ^▽^).
- But because the idea is relatively simple, so the code is not concise, the latter can continue to improve.
- There are some small aspects that are not considered clearly and have some minor errors.
- We are planning to do all the tasks together, but because of the difference in time, and although the discussion is effective, there are differences in the place
is the place to focus on, and everyone has a different idea, we have to rely on some of their own strength to accomplish some things, rather than meet the whole problem without thinking on their own
In order to be more efficient and team members able to demonstrate their capabilities, we have taken a division of labor.
In the production of the expression is mainly I write code, infix expression to the suffix expression is mainly my teammates to complete, of course, we have mutual acceptance of each other's views,
And together with the code to modify and debug, so that more efficient completion of our self-learning tasks
Estimate the completion time of each part of the project
PSP2.1 |
Personal software Process Stages |
Estimated time-consuming (hours) |
actual time elapsed (hours) |
Planning |
Plan |
1 |
5/6 |
Estimate |
Estimate how long this task will take |
0.5 |
|
Development |
Development |
16 |
|
Analysis |
Demand analysis (including learning new technologies) |
4 |
|
Coding Standard |
Code specification (to develop appropriate specifications for current development) |
0.5 |
0.5 |
Design UML |
Design Project UML class diagram |
1 |
|
Coding |
Specific code |
18 |
|
Code Review |
Code review |
2 |
|
Test |
Test (self-test, modify code, commit changes) |
2 |
|
Size Measurement |
Calculation effort (actual time) |
0.5 |
|
Postmortem & Process Improvement Plan |
Summarize afterwards and propose process improvement plan |
3 |
|
|
Total |
48.5 |
|
Resources
2017-2018-2 20172310 "Java Programming" course pair programming Exercises _ arithmetic _ first week