标签:idt 展示 static 技术 div tle count app int
需求分析:
随机生成算式题目以及其结果
具体设计:
一个随机生成算式的方法Make()
一个计算结果的方法JiGuo()
具体编码:
Make()
public static String Make(){ StringBuilder bu = new StringBuilder(); int count = (int) (Math.random() * 2) + 1; int start = 0; int number1 = (int) (Math.random() * 99) + 1; bu.append(number1); while (start <= count){ int op = (int) (Math.random() * 3); int number2 = (int) (Math.random() * 99) + 1; bu.append(st[op]).append(number2); start ++; } return bu.toString(); }
JeGuo()
public static String JieGuo(String ma){ Stack<String> St = new Stack<>(); Stack<Character> Stack = new Stack<>(); int len = ma.length(); int k = 0; for(int j = -1; j < len - 1; j++){ char Char =ma.charAt(j + 1); if(j == len - 2 || Char == ‘+‘ || Char == ‘-‘ || Char == ‘/‘ || Char == ‘*‘) { if (j == len - 2) { St.push(ma.substring(k)); } else { if(k < j){ St.push(ma.substring(k, j + 1)); } if(Stack.empty()){ Stack.push(Char); }else{ char sChar = Stack.peek(); if ((sChar == ‘+‘ || sChar == ‘-‘) && (Char == ‘*‘ || Char == ‘/‘)){ Stack.push(Char); }else { St.push(Stack.pop().toString()); Stack.push(Char); } } } k = j + 2; } } while (!Stack.empty()){ St.push(Stack.pop().toString()); } Stack<String> calcStack = new Stack<>(); for(String peekChar : St){ if(!peekChar.equals("+") && !peekChar.equals("-") && !peekChar.equals("/") && !peekChar.equals("*")) { calcStack.push(peekChar); }else{ int a1 = 0; int b1 = 0; if(!calcStack.empty()){ b1 = Integer.parseInt(calcStack.pop()); } if(!calcStack.empty()){ a1 = Integer.parseInt(calcStack.pop()); } switch (peekChar) { case "+": calcStack.push(String.valueOf(a1 + b1)); break; case "-": calcStack.push(String.valueOf(a1 - b1)); break; case "*": calcStack.push(String.valueOf(a1 * b1)); break; default: calcStack.push(String.valueOf(a1 / b1)); break; } } } return ma + "=" + calcStack.pop(); }
结果展示:
PSP:
PSP阶段 |
预计花费时间(分钟) |
实际花费时间(分钟) |
计划 |
30 |
30 |
.明确需求和其它相关因素,估计每个阶段的时间成本 |
30 |
30 |
开发 |
325 |
385 |
.需求分析 |
40 |
60 |
.代码规范 |
35 |
35 |
.具体设计 |
45 |
60 |
.具体编码 |
120 |
140 |
.代码复审 |
45 |
50 |
.测试(自测,修改代码,提交修改) |
40 |
40 |
总结:
自己掌握的知识非常少,很多东西都是百度搜索,各种方法学过见过,一看就会,一写就废。应更加系统的练习,理解,编写。
标签:idt 展示 static 技术 div tle count app int
原文地址:https://www.cnblogs.com/tqz521127/p/14644139.html