First, the needs analysis
(1) automatically generates four arithmetic operation of Equation 2 number less than 10 100 (+ - * /), operation results are required within 100
Number (2) title can be customized
(3) 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
(4) generating operation to an external file title stored in text.txt
Second, the functional design
Basic functions: automatic generation of four arithmetic questions
Extensions: (1) calculate the answer
(2) the user can choose by subtraction, multiplication and division, plus or minus, aliquot
Third, the design and implementation
Design of a Test class, including the definition of variables, variable assignments, determines statements, loops, and finally testing.
Fourth, the test run
1 comprises a subtraction, free of positive and negative, and the choice of the number of the number of items.
2. Include arithmetic, non-negative, and the choice of the number of the number of items.
3 contains only addition and subtraction, containing positive and negative, and the choice of the number of the number of items.
4. comprise arithmetic, containing positive and negative, and the choice of the number of the number of items.
V. snippet
1. The operation of the control block.
// 进行输入条件 Scanner reader = new Scanner(System.in); System.out.println("请输入题目数量"); count = reader.nextInt(); System.out.println("请输入题目范围,100or1000"); fanwei = reader.nextInt(); System.out.println("请输入是否有负数,0为无负数,1为有负数"); fushu = reader.nextInt(); System.out.println("请输入是否带有乘除法,0无1有"); p1 = reader.nextInt(); for (i = 0; i < count; i++) { String r1 = "";// 如有负数,且负数为num1,则有括号 String r2 = "";// 如有负数,且负数为num2,则有括号 p2 = (int) (Math.random() * 4);// char jia = '+'; char jian = '-'; char cheng = '*'; char chu = '/'; char j=' '; if (fushu == 0) { num1 = (int) (Math.random() * fanwei); r1= ""+num1; num2 = (int) (Math.random() * fanwei); r2 = "" + num2; } else { num1 = (int) (Math.random() * fanwei * (Math.random() > 0.5 ? 1: -1)); if (num1 < 0) { r1 = "(" + num1 + ")"; } else { r1 = "" + num1; } num2 = (int) (Math.random() * fanwei * (Math.random() > 0.5 ? 1: -1)); if (num2 < 0) { r2 = "(" + num2 + ")"; } else { r2 = "" + num2; } }
// 判断是否有乘除法 switch (p2) { case 0:j='+'; sum = num1 + num2; if (num1 + num2 <= 100) { break; } case 1:j='-'; sum = num1 - num2; if (num1 - num2 < 100) { } break; case 2:j='*'; sum = num1 * num2; switch (p1) { case 1: if (num1 * num2 <= 100) { break; } case 0: i--; continue; } break; case 3:j='/'; sum = num1 / num2; switch (p1) { case 1: if (num1 / num2 <= 100) { break; } case 0: i--; continue; } break; }
2.生成的运算题存储到外部文件test.txt中代码块。
//第一部分 PrintWriter over; try{ over=new PrintWriter("E:/test.txt");//输出的路径和文件名 }catch(FileNotFoundException e){throw new RuntimeException(e);} //第二部分 over.println("第" + (i + 1) + "题:" + r1 + "" + j + "" + r2 + "=" + sum + ""); over.flush();//
六、总结
首先整理好思路,把基本框架建立出来。进一步利用循环,选择,判断等方法书写程序。最后整体测试,改错。我在具体编写代码过程中估计和实践相差巨大,因为在编写代码时有不懂得地方查阅了以下资料,导致最后与估计事件相差过多。
七、PSP
PSP2.1 |
任务内容 |
计划共完成需要的时间(min) |
实际完成需要的时间(min) |
Planning |
计划 |
30 |
40 |
· Estimate |
· 估计这个任务需要多少时间,并规划大致工作步骤 |
15 |
20 |
Development |
开发 |
480 |
660 |
·· Analysis |
需求分析 (包括学习新技术) |
10 |
20 |
· Design Spec |
· 生成设计文档 |
0 |
0 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
0 |
0 |
· Coding Standard |
代码规范 (为目前的开发制定合适的规范) |
5 |
5 |
· Design |
具体设计 |
15 |
20 |
· Coding |
具体编码 |
480 |
600 |
· Code Review |
· 代码复审 |
10 |
10 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
20 |
50 |
Reporting |
报告 |
30 |
60 |
·· Test Report |
· 测试报告 |
20 |
25 |
· Size Measurement |
计算工作量 |
0 |
0 |
· Postmortem & Process Improvement Plan |
· 事后总结 ,并提出过程改进计划 |
10 |
15 |