20172307 Pair programming project - summary of the first week of four arithmetic operations
paired object
- Student ID: 20172311
- Name: Zhao Xiaohai
- Partner's first week blog address: ( http://www.cnblogs.com/zhaoxiaohai/p/8976043.html )
- Roles: (1) Driver: Zhao Xiaohai
(2) Co-pilot: Huang Yutang
demand analysis
- Generate four arithmetic questions, and realize the grading and number of questions.
- Convert infix expressions into postfix expressions, calculate the result of the question, and compare it with the answer entered by the user.
- Realize the operation of true fractions in the operation problem.
- Expansion requirements: To achieve de-duplication of topics.
Design ideas
1.UML class:
2. Ideas
- Generate a class that generates questions, output as a string. Realize the grading of questions, and the number is solved by while and for loops.
- The infix to suffix is realized by referring to the teacher's PPT and using the stack method.
- The realization of the true fraction is realized with reference to the example problem RationalNumber in the book.
- There is no idea of how to de-duplicate the topic.
Related process screenshots
Generate a Fraction of a minimal fractional class:
public class Fraction {
int numerator, denominator;
public Fraction() {
numerator= (int) (Math.random()*51);
denominator= (int) (Math.random()*51);
if(denominator==0)
denominator=1;
reduce();
}
public void reduce() {
if (numerator != 0) {
int common = gcd(Math.abs(numerator), denominator);
numerator = numerator / common;
denominator = denominator / common;
}
}
private int gcd(int num1, int num2) {
while (num1 != num2)
if (num1 > num2)
num1 = num1 - num2;
else
num2 = num2 - num1;
return num1;
}
public String getFraction()
{
String result;
if(numerator==0)
result="0";
else
if(denominator==1)
result=numerator+"";
else
result=numerator+"/"+denominator;
return result;
}
}
2. Generate a Create class to generate the title:
public class Create {
String[]Arraylist;
int num,rate;
public Create(int num ,int rate)
{
this.num=num;
this.rate=rate;
Arraylist=new String[num];
}
public String questionRate(int a)
{
String express="";
String[]OC={"+","-","×","÷"};
for (int c=0;c<a;c++) {
Fraction b = new Fraction();
String d=b.getFraction();
String e=OC[(int) (Math.random() * 4)];
while (d=="0"&&e=="÷") {
Fraction f=new Fraction();
d = f.getFraction();
}
express +=d+" "+e+ " ";
}
Fraction c=new Fraction();
String e=c.getFraction();
while (express.charAt(4*rate-1)=='÷'&&e=="0")
{
Fraction d=new Fraction();
e=d.getFraction();
}
express+=e+" "+"=";
return express;
}
public void QuestionNum(){
Create F=new Create(num,rate);
for(int a=0;a<num;a++)
Arraylist[a]=F.questionRate(rate);
}
public String[] getArraylist() {
return Arraylist;
}
public String getArraylist2(int a)
{
String b;
b=Arraylist[a];
return b;
}
public String toString() {
String a="";
for (int b=0;b<num;b++)
a+=Arraylist[b]+"\n";
return a;
}
}
3. Screenshot of the running of the CreatTest class
Difficulties and Solutions
- When running CreateTest, it shows that the array storing the String type is out of bounds
Prompt error:
- The solution process
and pairing partner Zhao Xiaohai read it several times in a row, but still did not see the error. Finally, under the guidance of the class teacher, Mr. Wang, I understood that the problem was when we declared the array. A variable, resulting in an array size of only 1.
Screenshot of the previous code:
Screenshot of the modified code:
Evaluation of twinning partners
In this pairing activity, Xiaohai played the role of the navigator. He completed the idea of the code, and he contributed a lot more than me. I hope I can help him more in the next few weeks of cooperation.
PSP time statistics
PSP2.1 | Personal Software Process Stages | Estimated time (minutes) | Actual time (minutes) |
---|---|---|---|
Planning | plan | 60 | 70 |
Estimate | Estimate how long this task will take | 30 | 30 |
Development | develop | 600 | |
Analysis | Requirements analysis (including learning new technologies) | 120 | 180 |
Coding Standard | Code Specifications (to develop appropriate specifications for current development) | 30 | 20 |
Design UML | Design project UML class diagram | 60 | 90 |
Coding | specific code | 180 | |
Code Review | code review | 180 | |
Test | Testing (self-testing, modifying code, committing changes) | 120 | |
Size Measurement | Computational workload (actual time | 30 | |
Postmortem & Process Improvement Plan | Post-event summary, and propose a process improvement plan | ||
total | 1410 |