20165205 2017-2018-2 "Java programming" a first-week summary of requirements analysis
The calculation of the input formula requires that the condition be met:
- Integer operations such as 2+5,47+7865 are supported.
- Supports multi-operator operations, such as 6/9+4/9,4+7*9.
- Supports fractional operations (true fractions), such as 3/4.
- High correct rate
- have input prompt
- Ability to handle illegal input (return exception)
Expansion requirements:
- Support automatic generation of topics
Multi-lingual support
Design ideas
- Writing the main class
Arithmetic4
Write the ArithmeticFunc
class to implement the calculation, including: Add, subtract, multiply, divide, Zhifang, prescribe the method, also contains the method that throws the exception.
Core code and comments
To calculate the content, take the addition method as an example:
public void Add (String s)//addition {string[] Str=s.split ("\\+"); if (Str[0].indexof ("/") >-1 | | str[1].indexof ("/") >-1)//score {string[] Str1=str[0].split ("[/]"); String[] Str2=str[1].split ("[/]"); if (Integer.parseint (str1[1])! = 0 && integer.parseint (str2[1])! = 0)//denominator not zero {result =simplefrac tion (((Integer.parseint (str1[0) *integer.parseint (str2[1]) + (Integer.parseint (str2[0]) *integer.parseint (str1[1 ])), (Integer.parseint (str1[1]) *integer.parseint (str2[1])); }else{throw new IllegalArgumentException ("Divisor cannot be zero!"); /divisor is zero throw exception}} else{//integer if (integer.parseint (str[0]) <1000&&integer.parseint (str[1]) <100 0&&integer.parseint (Str[0]) >-1000&&integer.parseint (str[1]) >-1000) {result = Inte Ger.parseint (Str[0]) +integer.parseint (str[1]) + ""; } else{throw new IllegalArgumentException ("overrun!");} Throw exception when value range exceeds}}
Throw exception operator: Take subtraction as an example
if(s.indexOf("-")>-1){ int i=s.indexOf("-"); if(s.indexOf("-",i+1)==i+1){ throw new IllegalArgumentException("Input error! Don‘t like 1--1");//格式错误时抛出异常 }else{ substract(s); }
Test method
Code hosting reviews for pair of small partners
- Pair of partners: 20165233 Zhang Yuxin
- I've been talking to my partner for a long time. The design of the code, after learning the teacher for the stack of code to get some inspiration, so write out the first frame, the different operators to filter, and then for the different operators to do the operation, so that the completion of this code.
PSP Table
Psp |
Personal Software Process Stages |
Estimated time-consuming (minutes) |
Actual time elapsed (minutes) |
Planning |
Plan |
30 |
45 |
Estimate |
Estimate how long this task will take |
180 |
180 |
Development |
Development |
100 |
130 |
Analysis |
Demand analysis (including learning new technologies) |
130 |
140 |
Design Spec |
Creating a design Document |
100 |
65 |
Design Review |
Design Review (and colleagues review design documents) |
30 |
20 |
Coding Standard |
Code specification (to develop appropriate specifications for current development) |
20 |
40 |
Design |
Specific design |
50 |
60 |
Coding |
Specific code |
45 |
30 |
Code Review |
Code review |
15 |
15 |
Reporting |
Report |
60 |
90 |
Test Report |
Test report |
30 |
45 |
Postmortem & Process Improvement Plan |
Summarize afterwards and propose process improvement plan |
10 |
25 |
|
Total |
880 |
985 |
Feelings
For this pair to write code, I feel the 1+1>2 feeling, in the process of writing code two people can timely rewrite the incorrect code, and can get new ideas, and make our code more perfect, more rigorous. At the same time also can find their own knowledge of loopholes, to supplement, really is wonderful AH.
20165205 2017-2018-2 "Java programming" a first week summary of pair programming