20194641-- automatically generates four arithmetic test report

 

First, the needs analysis:

For the preparation of a primary computing applet four operations, program parameters can be customized, and the generated equation result.txt stored in the external file.

Second, the functional implementation:

·basic skills

(1) automatically generates four arithmetic operation of Equation 2 number less than 10 100 (+ - * /), operation results are required within 100

(2) discarding duplicates equation. = 2 + 3 + 3 = 2 and Equation 2 is repeated and 3 + = 3 + 2 = not repeated formula

Number (3) title can be customized

(4) parameters can be controlled

          Whether to include multiplication and division

          Controllable range values ​​of the operands (e.g., operands within 100 or within 1000)

          Whether operands containing negative    

  (5) generating operation to an external file title stored in result.txt

· Expansion capabilities

(1) the output of the equation were optimized: by giving all negative operand in parentheses is added, greatly improves the cleanliness of the equation, the equation enhance readability.

 Third, the design and implementation:

(1) using rand.nextInt () statements and (int) (Math.random () * number); statement to achieve for generating random numbers

int     A = rand.nextInt (100); // randomly generated integer in the range of 0-100 
int B = rand.nextInt (100); // randomly generated integer in the range 0-100

 

Asum[i]=(int) (Math.random()*number1);
Bsum[i]=(int) (Math.random()*number1);

 (2) The four operators stored in an array of char, using (int) (Math.random () * number) statement generates four random expression;

 

char Opera [] = { '+', '-', '*', '/'}; // Opera [0] ~ Opera [. 3] are sequentially output "+", "-", "*", "/ " 
int R & lt = ( int ) (Math.random () * number3); // Analyzing OUT +, -, *, /

 

 

 (3) using the PrintStream sun = new PrintStream ( "d: /result.txt"); statement stored in the generated equations result.txt document;

PrintStream ps = new PrintStream("d:/result.txt");
System.setOut(ps);

(4) using the int number1 = reader.nextInt (); the number of items to achieve controllable;

 

System.out.println ( "Enter the number of equations" );
         int number2 = reader.nextInt ();
         int Bsum [] = new new  int [number2];

 

 

 

(5) to achieve a controllable range of values ​​of the operands;

 

System.out.println ( "number of input control range" );
         int number1 = reader.nextInt ();
         int ASUM [] = new new  int [number1];

 

( 6) to achieve a negative value calculation;

 

char Opera2 [] = { '', '-'}; // Opera [0] ~ Opera [. 1] are sequentially output "(space)", "-" 
int n-= ( int ) (Math.random () * number4 ); // The first value is negative if 
int m = ( int ) (Math.random () * number4); // second whether the value is negative

 

(7) to achieve all negative values ​​in brackets;

char Opera3 [] = { '', '(', ')'}; // Opera [0] ~ Opera [2] sequentially outputs "(space)", "(", ")" 
int R & lt = ( int ) (Math.random () * number3); // Analyzing OUT +, -, *, /

(8) In addition to re-implement the equation operation;

Asum[0]=(int) (Math.random()*number1);
            Bsum[0]=(int) (Math.random()*number2);
        for(int i=1;i<number2;) {
            Asum[i]=(int) (Math.random()*number1);
            Bsum[i]=(int) (Math.random()*number1);
            if(Asum[i]!=Asum[i-1]) {
                i++;
            }
        }

 

 

 

 Fourth, the test run:

(1) basic needs test run

 

 (2) development needs test run

 

 

Five more satisfied snippet:

char Opera[]= {'+','-','*','/'};//Opera[0]~Opera[3]依次输出“+”,“-”,“*”,“/”
char Opera2[]= {' ','-'};//Opera[0]~Opera[1]依次输出“ (空格)”,“-”
char Opera3[]= {' ','(',')'};//Opera[0]~Opera[2]依次输出“ (空格)”,“(”,“)”

 

for(int i=0;i<number2;i++) {
int n=(int) (Math.random()*number4);//第一个数值是否为负数
int m=(int) (Math.random()*number4);//第二个数值是否为负数
int r=(int) (Math.random()*number3);//判断输出+,-,*,/

System.setOut(ps);
System.out.printf("%c%c%d%c%c%c%c%d%c=\r",Opera3[n*1],Opera2[n],Asum[i],Opera3[n*2],Opera[r],Opera3[m*1],Opera2[m],Bsum[i],Opera3[m*2]);
System.out.println();
}

 

六、总结:

对新技术的学习能力还需要加强。把所有的方法和对象都放到了一个类中进行了实现,代码的结构层次不明显。

七、PSP

PSP2.1 任务内容 计划共完成需要的时间(h) 实际完成需要的时间(h)
Planning 计划 0.5 1
· Estimate · 估计这个任务需要多少时间,并规划大致工作步骤 18.3 27.4
Development 开发 5 8
·· Analysis 需求分析 (包括学习新技术) 3 5
· Design Spec · 生成设计文档 0.5 0.6
· Design Review · 设计复审 (和同事审核设计文档) 0.5 0.5
· Coding Standard 代码规范 (为目前的开发制定合适的规范) 0.2 0.4
· Design 具体设计 2 2
· Coding 具体编码 2 2
· Code Review · 代码复审 1 1.5
· Test · 测试(自我测试,修改代码,提交修改) 3 6
Reporting 报告 0.5 0.5
·· Test Report · 测试报告 0.2 0.2
· Size Measurement 计算工作量 0.2 0.2
· Postmortem & Process Improvement Plan · 事后总结 ,并提出过程改进计划 0.5 0.5

Guess you like

Origin www.cnblogs.com/sunshuaiqun/p/11524998.html