伙伴第一周博客地址html
可独立使用(能实现本身编写测试类单独生成题目的功能)
可生成不一样等级题目,相似于:
1级题目:2 + 5 = 、10 - 5 = 之类的两个数,一个运算符的题目java
(2).题目运算(判题)
可独立使用,实现中缀表达式转为后缀表达式并计算;判断用户答题正误,并输出正确结果dom
可独立使用,实现分数算式的计算学习
可独立使用,实现对自动生成表达式的去重:以下若生成:2 + 5 = & 5 + 2 = 为同一题目测试
第一部分:生成题目编码
import java.util.Stack; import java.util.Random; import java.util.ArrayList; import java.util.Scanner; class Questions { ArrayList<Object> array = new ArrayList<Object>(); Random generator = new Random(); char[] newchar = {'+', '-', '*', '/'}; protected int number; int NUM; public Questions() { number = 0; } public Object getQuestion(int num) { int num1 = num; while (num > 0) { int figure = (int) generator.nextInt(9) + 1; array.add(figure); number = (int) (Math.random() * 4); array.add(newchar[number]); num--; } String obj = ""; while (num < 2 * num1) { obj += array.get(num); num++; } int other = (int) generator.nextInt(9) + 1; array.add(other); obj += other + "="; return obj; } }
第二部分:题目运算设计
//生成后缀表达式 public class Calculations { public static void main(String[] args) { Questions questions=new Questions(); Stack stack = new Stack(); Scanner Scan=new Scanner(System.in); char c; int count=0,answer; char[] operation = new char[100]; String str = (String) questions.getQuestion(3); System.out.println("请回答如下问题:\n"+str); System.out.println("请输入你的答案:"); answer=Scan.nextInt(); for (int i = 0; i < str.length(); i++) { c = str.charAt(i); if (c >= '0' && c <= '9') { operation[i] = c; count++; } else { if (c == '*' || c == '/') { if (stack.empty()) { stack.push((char) c); } else if ((char) stack.peek() == '*' || (char) stack.peek() == '/') { operation[i] = (char) stack.pop(); stack.push(c); } else stack.push(c); } else if (c == '+' || c == '-') { if (stack.empty()) { stack.push(c); } else if ((char) stack.peek() == '+' || (char) stack.peek() == '-') { operation[i] = (char) stack.pop(); stack.push(c); } else { operation[i] = (char) stack.pop(); stack.push(c); } } else stack.push(c); } } int num = stack.size(); for (int a = 0; a < num; a++) { operation[str.length() + a] = (char) stack.pop(); }
//后缀表达式计算 Stack<Integer> stack1 = new Stack<Integer>(); int m, n, sum,num1=str.length()+(str.length()-count); for (int b = 0; b <= num1; b++) { if (operation[b] >= '0' && operation[b] <= '9') stack1.push((int) operation[b]-48); else { if (operation[b] == '+') { m = stack1.pop(); n = stack1.pop(); sum = n + m; stack1.push(sum); } else if (operation[b] == '-') { m = stack1.pop(); n = stack1.pop(); sum = n- m; stack1.push(sum); } else if (operation[b] == '*') { m = stack1.pop(); n = stack1.pop(); sum = n * m; stack1.push(sum); } else if (operation[b] == '/') { m = stack1.pop(); n = stack1.pop(); sum = n / m; stack1.push(sum); } else if (operation[b] == ' ') continue; } } if ((int)stack1.peek()==answer) System.out.println("恭喜你答对了!"); else System.out.println("很遗憾,答错了!答案是:"+stack1.peek()); } }
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) |
---|---|---|
Planning | 计划 | 60 |
Estimate | 估计这个任务须要多少时间 | 3 |
Development | 开发 2000 | 3000 |
Analysis | 需求分析 (包括学习新技术) | 350 |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 60 |
Design UML | 设计项目UML类图 | 60 |
Coding | 具体编码 | 1500 |
Code Review | 代码复审 | 30 |
Test 测试 | (自我测试,修改代码,提交修改) | 300 |
Size Measurement 计算工做量(实际时间 ) | 2 | 2 |
Postmortem & Process Improvement Plan | 过后总结, 并提出过程改进计划 | 30 |
合计 | 4395 |