20172311 "Java Programming" Course Pair Programming Exercise_Four Algorithms First Week Phase Summary
pairing partner
Student ID: 20172307
Name: Huang Yutang
Partner's first week blog address:
demand analysis
<1> Functional requirements
1. Automatically generate questions
Can be used independently (can realize the function of writing test classes to generate questions independently)
Different levels of questions can be generated, similar to:
Level 1 questions: 2 + 5 =; two numbers like
10 - 5 =
, a question for an operator
2. Problem operation (judgment problem)
Can be used independently
Convert infix expressions to postfix expressions and calculate
Determine whether the user's answer is right or wrong, and output the correct result
3. Support True Score
Can be used independently
Implement fractional calculations
3. De-duplication of topics (expansion requirements, extra points)
Can be used independently
Implement deduplication of automatically generated expressions: as follows
If generated: 2 + 5 =;
5 + 2 =
for the same topic<2> Understanding of needs
1. There must be a class that generates random questions. The numbers in the questions may be fractions or integers. 2. There must be a class that converts infix expressions into postfix expressions
3. There must be a class that calculates suffix expressions
4. There must be a class that judges the subject
5. Combine the above classes to write the product code<3> Possibilities of follow-up expansion
The specific topic de-emphasis idea has not yet been produced, and the problem should not be big.
Design ideas
NML class diagram
Idea:
There must be a class that can generate random minimal scores, and apply it to the class that generates random questions. At the same time, there must be a space character between the numbers and operators in the generated questions, which is convenient for converting into suffix expressions. When using a stack, use the stack. Finally, we need to achieve interaction, that is, let the customer answer the question, and then the system judges whether it is correct and tells the customer.Related process screenshots
A class that generates random minimal fractions
Fraction
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;
}
}
- A class that generates the corresponding number expression
Create
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;
}
}
CreateTest
Screenshot of test class running
Difficulties encountered and solutions
- There was a logic error when I first started writing a class that generates a question of type integer, which resulted in an out of bounds run of the test class.
The screenshot of the error code is as follows:
The result of running the test class is as follows:
The screenshot of the modified code is as follows:
Analysis of the cause of the error: The area marked by the red circle in the error code is where the error lies. This statement creates an empty array, which is contrary to the original intention of creating an array that stores num String expressions. This leads to the phenomenon of cross-border. In the modified code, the array is instantiated in the constructor, and the purpose is achieved.
Comment on paired friends
The advantage of pairing with Huang Yutang's children's shoes is that he can listen to some of my ideas very seriously, and at the same time, he can put forward his own supplementary suggestions for my ideas, and he is very patient and helpful. When I am tired of typing code, he will Take the initiative to help me relay. The disadvantage may be that the requirements for yourself are not strict enough when writing code, and sometimes there are some input errors. On the whole, the pair learning with Huang Yutang children's shoes is very pleasant, and I hope to make persistent efforts in the next pair programming project and make progress together! !
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 |