20,194,655 second software engineering jobs

A. Requirements Analysis

(1) to automatically generate the four arithmetic operations of equation 2 operands within 100 10 (+ - * /)

(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

     是否包含乘法和除法

     操作数数值范围可控(如操作数 在100以内   还是1000以内)

     操作数是否含负数    

(5) generated the title stored in the external file operation result.txt in
two functional design
1. adding a random number to achieve

    r1[i]=(int)(number3+Math.random()*(number4-number3));
    r2[i]=(int)(number3+Math.random()*(number4-number3));   

    S1[i]=(r1[i]+r2[i]);

  2.然后生成随机运算符

     建立了一个数组r3,将运算符存储在数组r3中

     static String[] r3={"+","-","*","/"};

  3.能够确保生成符号加减乘除计算

The basic function of
automatic generation of four arithmetic operation of Equation 2 number of less than 10 100 (+ - * /), operation results are required within 100

Excluding repeated formula. = 2 + 3 + 3 = 2 and Equation 2 is repeated and 3 + = 3 + 2 = not repeated formula

The number of items can be customized

Related parameters controllable

Multiplication and division contain
controlled range (e.g., within 100 or operand within 1000) Numerical operand
Operand containing negative whether
operational problems generated to an external file stored in result.txt

extensions

(1) to automatically generate the four arithmetic operations within 100

(2) Related parameters can be controlled

(3) may control the numerical range operand

是否包括负数

是否包括乘法或者除法

(4) generated the title stored in the external operation

  1. Design and implementation:
    Use the constructor PrintStream Scanner, PrintStream ps = new PrintStream ( "d: /result.txt");

System.setOut (ps); call this function, you can all System.out.println (); output statement, to print i file we created folder

Scanner t = new Scanner (System.in); We control input from the keyboard

Math.random (); generating a random function is not repeated, I did the following test

  1. Test run:

5. snippet:
// select the first operand
2 int A = (int) (Math.random () TF +. 1);
. 3
. 4 IF (ZF ==. 1) {// there are negative numbers
5 int p = (int) (Math.random ()
2);
. 6 Switch (P) {
. 7 Case 0: A = A * (-. 1); // negated
. 8 of System.out.print (A); BREAK;
. 9. 1 Case :
10 of System.out.print (A); BREAK;
. 11}
12 is}
13 is IF (ZF == 0) {// no negative
14 of System.out.print (A);
15}
`` `

Select operation symbol
`` `java

 1 System.out.println("请选择是否包含*或者/:2:否 4:是 ");
 2         int fu=t.nextInt();
 3 if(fu==2) {//选择两个字符‘+’‘-’
 4                 int k=(int)(Math.random()*2);
 5                 switch(k) {//随机选择运算符
 6                 case 0:System.out.print("+");
 7                        break;
 8                 case 1:System.out.print("-");
 9                        break; 
10                                                }
11 if(fu==4) {//四个字符的‘+’‘-’‘*’‘/’
12             int k=(int)(Math.random()*4+1);
13             switch(k) {//随机选择运算符
14             case 1:System.out.print("+");break;
15             case 2:System.out.print("-");break;
16             case 3:System.out.print("*");break;
17             case 4:System.out.print("/");break;
18             }

The right side of the equal sign results

 1 //等号
 2             
 3             System.out.print("=");
 4             //运算结果
 5             if(k==1) {
 6                 c=a+b;System.out.println(c);
 7             }
 8             if(k==2) {
 9                 c=a-b;System.out.println(c);
10             }
11             if(k==3) {
12                 c=a*b;System.out.println(c);
13             }
14             if(k==4) {
15                 c=a/b;System.out.println(c);
16             }

6. Summary
design four arithmetic algorithm, after running correct, the code is incremented by one according to the functional requirements, each additional step of the test, after the test is correct, write a function

7.PSP

Guess you like

Origin www.cnblogs.com/12yy/p/11519481.html