首先要輸入生成題目的數目mhtml
package CaculateSystem; import java.util.Random; public class ProduceProblem { public int ProduceProblem () { String s = ""; Random shu = new Random();//每一個運算式的隨機數 int count = 1; //記錄符號; char[] operator = new char[]{'+', '-', '*', '/'}; int m = 2 + (int) (Math.random() * 6); //每一個運算式數目的個數 for (int j = 0; j < m; j++) { int num = shu.nextInt(10); s = s +" "+ num; if (count < m) { int c = shu.nextInt(4); s = s +" "+ operator[c]; count++; } } String [] str = s.split(" "); System.out.println(s + "="); Translate t = new Translate(str); return t.flag; } }
package CaculateSystem; import java.util.Stack; public class Translate extends Judge{ int flag; public Translate (String[] args) { Stack<String> z = new Stack<String>(); String jieguo = ""; String t = ""; for (int i = 0; i < args.length; i++) { switch (args[i]) { case "(": z.push(args[i]); break; case "+": case "-": while(z.empty() != true) { t = z.pop(); if (t.equals("(")) { z.push(t); break; } jieguo = jieguo + t + " "; } z.push(args[i]); break; case "*": case "/": while(z.empty() != true) { t = z.pop(); if (t.equals("+") || t.equals("-") || t.equals("(")) { z.push(t); break; } jieguo = jieguo + t + " "; } z.push(args[i]); break; case ")": while (z.empty()== false) { t = z.pop(); if (t.equals("(")) { break; } else { jieguo = jieguo + t + " "; } } break; case" ": break; default: jieguo = jieguo + args[i] + " "; break; } } while (z.empty() == false) { jieguo = jieguo + z.pop() + " "; } String [] str = jieguo.split(" "); Count py = new Count(str); int answer = py.answer; flag = A(answer); } public Translate() { } }
package CaculateSystem; import java.util.Random; public class CreatOpNum { Rational opNum = new Rational(); Random random = new Random(); String opnumFile = ""; String opnumPri = ""; int flag; CreatOpNum(int flag1) { flag = flag1; int a = random.nextInt(9)+1; opNum.setNumerator(a); if (flag1 == 1) {//是分數 int b = random.nextInt(9)+1; while (b == 0) { b = random.nextInt(9)+1; } opNum.setDenominator(b); } else {//不是分數 opNum.setDenominator(1); } } public void getOpNumFile() { opnumFile = opNum.getNumerator() + " / " + opNum.getDenominator(); } public void getOpNumPri() { if (flag == 0) { opnumPri = opNum.getNumerator() + "";//輸出整數 } else if (opNum.getNumerator() > opNum.getDenominator()) {//假分數 int n = opNum.getNumerator() / opNum.getDenominator(); int m = opNum.getNumerator() % opNum.getDenominator(); opnumPri = n + " + " + m + " / " + opNum.getDenominator(); } else { opnumPri = opNum.getNumerator() + " / " + opNum.getDenominator(); } } }
package CaculateSystem; public class Rational {//有理數 int numerator = 1;//分子 int denominator = 1;//分母 void setNumerator(int a) {//設置分子 int c = f(Math.abs(a), denominator);//計算最大公約數 numerator = a / c; denominator = denominator / c; if (numerator < 0 && denominator < 0) { numerator = -numerator; denominator = -denominator; } } void setDenominator(int b) {//設置分母 int c = f(numerator, Math.abs(b));//計算最大公約數 numerator = numerator / c; denominator = b / c; if (numerator < 0 && denominator < 0) { numerator = -numerator; denominator = -denominator; } else if (numerator > 0 && denominator < 0) { numerator = -numerator; denominator = -denominator; } } int getNumerator() { return numerator; } int getDenominator() { return denominator; } int f(int a, int b) {//求a,b的最大公約數 if (a == 0) { return 1;//c爲分母不能爲0 } if (a < b) {//令a>b int c = a; a = b; b = c; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } Rational add(Rational r) {//加法運算 int a = r.getNumerator();//返回有理數r的分子 int b = r.getDenominator();//返回有理數r的分母 int newNumerator = numerator * b + denominator * a;//計算出新分子 int newDenominator = denominator * b;//計算出新分母 Rational result = new Rational(); result.setNumerator(newNumerator); result.setDenominator(newDenominator); return result; } Rational sub(Rational r) {//減法運算 int a = r.getNumerator(); int b = r.getDenominator(); int newNumerator = numerator * b - denominator * a; int newDenominator = denominator * b; Rational result = new Rational(); result.setNumerator(newNumerator); result.setDenominator(newDenominator); return result; } Rational muti(Rational r) {//乘法運算 int a = r.getNumerator(); int b = r.getDenominator(); int newNumerator = numerator * a; int newDenominator = denominator * b; Rational result = new Rational(); result.setNumerator(newNumerator); result.setDenominator(newDenominator); return result; } Rational div(Rational r) {//除法運算 int a = r.getNumerator(); int b = r.getDenominator(); Rational result = new Rational(); if (a == 0) { System.out.println("分母/除數不能爲0"); result.setNumerator(0); System.exit(0); } else { int newNumerator = numerator * b; int newDenominator = denominator * a; result.setNumerator(newNumerator); result.setDenominator(newDenominator); } return result; } }
代碼託管java
挺開心個人同伴能接受與我組隊的請求,在這個階段的研討中他就像比喻中的副駕駛的位置,爲我觀察這我發現不了的坑,也在必要的分叉口給了我不少有用的建議,好比在生成隨機式子的時候我在弄出簡單的隨機生成以後,生成較長式子的算法就是由他提醒編寫的,固然這樣的狀況會有不少,我負責大致,而他就負責細節,檢查。他很好的在結對下扮演了一個領航員的位置。不過我以爲個人夥伴須要提高一下本身的自信,其實好多事情他均可以獨立很好的完成的。git
計劃 | 預估耗時(分鐘) | 實際耗時(分鐘) |
---|---|---|
估計這個任務須要多少時間 | 200 | 200 |
開發 | ||
需求分析 (包括學習新技術) | 120 | 150 |
生成設計文檔 | 30 | 30 |
設計複審 (和同事審覈設計文檔) | 60 | 75 |
代碼規範 (爲目前的開發制定合適的規範) | 90 | 105 |
具體設計 | 30 | 60 |
具體編碼 | 720 | 810 |
代碼複審 | 60 | 60 |
測試(自我測試,修改代碼,提交修改) | 90 | 90 |
報告 | ||
測試報告 | 20 | 20 |
計算工做量 | 10 | 10 |
過後總結, 並提出過程改進計劃 | 240 | 270 |
合計 | 1500 | 1710 |
http://www.cnblogs.com/math/p/se-tools-001.html
http://www.cnblogs.com/vertextao/p/6593339.html
http://www.cnblogs.com/Vivian517/p/8762830.html
https://blog.csdn.net/newgrammer/article/details/757522
https://en.wikipedia.org/wiki/Polish_notation算法