2.當咱們把正確率加上後,咱們的程序在運行時遇到分數出現了錯誤。
html
問題2解決方案:咱們的分數最終轉換出來是字符串型的,因此在前面應該定義一個字符串型變量c1來儲存,而後再去與後綴計算結果比對。
java
3.當我在改正問題二時只改正了c1 = scan.next();
而沒有改正if (ben.calculator(lastexpression).equals(String.valueOf(c1)))
因此出現了個人用戶哭死在我面前系列!
git
姓名 | 郭愷 | 段志軒 | 李馨雨 |
---|---|---|---|
學號 | 20172301 | 20172304 | 20172328 |
貢獻率(%) | 38% | 32% | 30% |
package 結對編程; import java.util.ArrayList; import java.util.Random; public class Arithmetic { char[] operator = {'+', '-', '*', '÷'}; Random generator = new Random(); int num1, num2, num3,num4, a; private String result=""; ArrayList<String> questionName = new ArrayList<>(); // 輸出1級題目:+、- public String level1() { num1 = generator.nextInt(20)+1; num2 = generator.nextInt(20)+1; num3 = generator.nextInt(2); a = generator.nextInt(1); result = num1 + " " + operator[num3] + " " + num2; for (int x = 0; x <= a; x++) { num2 = generator.nextInt(20)+1; num3 = generator.nextInt(2); result += " " + operator[num3] + " " + num2; } return result; } // 輸出2級題目:*、÷ public String level2() { num1 = generator.nextInt(20)+1; num2 = generator.nextInt(20)+1; num3 = generator.nextInt(2) + 2; a = generator.nextInt(3); result = num1 + " " + operator[num3] + " " + num2; for (int x = 0; x <= a; x++) { num2 = generator.nextInt(20)+1; num3 = generator.nextInt(2) + 2; result += " " + operator[num3] + " " + num2; } return result; } // 輸出3級題目:+、-、*、÷ public String level3() { num1 = generator.nextInt(20)+1; num2 = generator.nextInt(20)+1; num3 = generator.nextInt(4); result =""+ num1 + " "+ operator[num3] + " " + num2; a = generator.nextInt(3); for (int x = 0; x <= a; x++) { num3 = generator.nextInt(4); num4 = generator.nextInt(2); num2 = generator.nextInt(20)+1; if(a!=0) { result += " " + operator[generator.nextInt(2)] ; } a--; result += " "+Arithmetic.bracket() + " " + operator[num3]+ " " + num2 ; } return result; } //生成分數. public RationalNumber fraction() { int numer = generator.nextInt(20)+1; int denom = generator.nextInt(20)+1; RationalNumber a = new RationalNumber(numer, denom); if (numer > denom) if (numer % denom == 0) return a; else a = a.reciprocal(); else return a; return a; } //四級題目 public String level4() { Arithmetic[] fraction = new Arithmetic[5]; RationalNumber[] fraction1 = new RationalNumber[5]; for (int x = 0; x < fraction.length; x++) { Arithmetic a = new Arithmetic(); fraction1[x] = a.fraction(); } num3 = generator.nextInt(4); a = generator.nextInt(2); result = fraction1[0] + " " + operator[num3] + " " + fraction1[1]; if (a > 2) for (int x = 2; x < a; x++) { num3 = generator.nextInt(4); result += " " + operator[num3] + " " + fraction1[x]; } return result; } // 重寫toString方法 public String toString(int number) { String result1=""; result1= "問題" + number + ": " + result + " = "; return result1; } public String toString(){ String result = ""; result = this.result; return result; } //生成括號的方法。 public static String bracket() { char[] operator = {'+', '-', '*', '÷'}; Random generator = new Random(); int num1, num2, num3, num4,a; String result1; String ab; String []abc=new String [2]; num1 = generator.nextInt(20) + 1; num2 = generator.nextInt(20) + 1; num3 = generator.nextInt(4); num4 = generator.nextInt(2); ab = " "+ operator[num3]+" ( "+ (generator.nextInt(20)+1) +" "+ operator[num4]+ " "+(generator.nextInt(20)+1)+" ) "; abc[1]=ab; abc[0]=" "; result1 = num1 +abc[generator.nextInt(2)] + operator[num3]+" "+num2; return result1; } // public void }
package 結對編程; import java.util.ArrayList; import java.util.List; import java.util.Stack; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.List; import java.util.Stack; import java.util.StringTokenizer; public class Convert { List<String> expre; // expression 表達式 Stack<String> op; // 操做符 String result = ""; public Convert() { expre = new ArrayList<String>(); op = new Stack(); } // 中綴表達式轉後綴表達式的轉換方法。 public String transit(String q) // question { String a; // a 是字符 StringTokenizer tokenizer = new StringTokenizer(q); while (tokenizer.hasMoreTokens()) { a = tokenizer.nextToken(); if (a.equals("(")) op.push(a); // 若是是"(",入棧 else if (a.equals("+") || a.equals("-")) { if (!op.isEmpty()) { if (op.peek().equals("(")) op.push(a); // 若是棧頂"(",運算符入棧 else { expre.add(op.pop()); // 先移除棧頂元素到列表中,再將運算符入棧 op.push(a); } } else { op.push(a); // 棧爲空,運算符入棧 } } else if (a.equals("*") || a.equals("÷")) { if (!op.isEmpty()) { if (op.peek().equals("*") || op.peek().equals("÷")) { expre.add(op.pop()); op.push(a); } else op.push(a); } else op.push(a); // 若是棧爲空,運算符入棧 } else if (a.equals(")")) { while (true) { String b = op.pop(); if (!b.equals("(")) { expre.add(b); } else { break; } } } else { expre.add(a); // 若是爲操做數,入列表 } } while (!expre.isEmpty() && !op.isEmpty()) { expre.add(op.pop()); } for (String x : expre) result += x + " "; return result; } }
package 結對編程; import java.util.Stack; import java.util.StringTokenizer; // 後綴表達式求值 public class Comparision { Stack<String> stack = new Stack<String>(); RationalNumber num1,num2,num3; public Comparision() { stack = new Stack<String>(); } public String calculator(String q) { String op1, op2, result; String a; StringTokenizer tokenizer = new StringTokenizer(q); while (tokenizer.hasMoreTokens()) { a = tokenizer.nextToken(); if(a.equals("+") || a.equals("-") || a.equals("*") || a.equals("÷")) { // 把棧頂的操做數彈出,轉換爲RationalNumber類型 op2 = stack.pop(); num2 = conToRantionalNum(op2); // 繼續把棧頂的操做數彈出,轉換爲RationalNumber類型 op1 = stack.pop(); num1 = conToRantionalNum(op1); //計算結果 result = calculate(num1,a.charAt(0),num2); stack.push(result.toString()); } else stack.push(a); } result = stack.pop(); return result; } public RationalNumber conToRantionalNum (String a) { String numer,denom; // numer分子,denom分母 // 把分數a/b以"/"爲標記分割開 StringTokenizer tokenizer1 = new StringTokenizer(a,"/"); numer = tokenizer1.nextToken(); if (tokenizer1.hasMoreTokens()) // 若是分母不爲1 { denom = tokenizer1.nextToken(); num1 = new RationalNumber(Integer.parseInt(numer), Integer.parseInt(denom)); } else // 若是分母爲1 { num1 = new RationalNumber(Integer.parseInt(numer), 1); } return num1; } // 計算+、-、*、÷ public String calculate(RationalNumber op1, char operation, RationalNumber op2) { RationalNumber result = new RationalNumber(0,1); switch (operation) { case '+': result = op1.add(op2); break; case '-': result = op1.subtract(op2); break; case '*': result = op1.multiply(op2); break; case '÷': result = op1.divide(op2); break; } return result.toString(); } }
package 結對編程; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Scanner; public class ArithmeticTest1 { public static void main(String []args) { Convert bee=new Convert(); Arithmetic num = new Arithmetic(); Comparision ben=new Comparision(); DecimalFormat fmt=new DecimalFormat("0.00"); NumberFormat fmt1= NumberFormat.getPercentInstance(); int a;//用戶輸入的等級數。 int b;//用戶想要作的題目數量。 int c = 0;//用戶算出所給題目的答案。 String c1;//專門爲level4設置的字符串類型的輸入。 int d;//用戶做對的題目數。 int e=0;//用戶答對的題目數. int ant=1;//題目編號數字. double f=0;//求出來正確率的小數數形式。 double h;//一共作的題目數量變成double型。 double i;//用戶作對的題目數量變成double型。 String another;////讓用戶輸出y/n的Scanner類型。 String lastexpression;//後綴表達式字符串型。; String luna;//轉化成的正確率百分數模式。 String ann; double abc;//將字符串小數點型正確率變成double型數字。 // paring abb=new paring(); Scanner scan = new Scanner(System.in); System.out.println("歡迎使用四則運算題庫!"); do{ System.out.println("請選擇題目難度等級(例如:1,2,3,4):"); a = scan.nextInt(); System.out.println("請選擇題目數量:"); b = scan.nextInt(); e=0; ant=1; switch (a) { case 1: for (int x = 0; x < b; x++) { num.level1(); System.out.print(num.toString(ant)); c = scan.nextInt(); ant++; // ann=abb.mmm(num.toString()); // if()若是正確,輸出恭喜答對,d++。不然輸出正確答案。 lastexpression= bee.transit(num.toString()); if (ben.calculator(lastexpression).equals(String.valueOf(c))) {System.out.println("恭喜答對"); e++;} else System.out.println("很遺憾,答錯了"+"正確答案是"+ben.calculator(lastexpression)); } h=(double)b; i=(double)e; f=i/h; luna= fmt.format(f); abc= Double.valueOf(luna);//把一個字符串表示的數字變成真正的數字. System.out.println("正確率是"+fmt1.format(abc)); System.out.println();//給題目換行 break; case 2: for (int x = 0; x < b; x++) { num.level2(); System.out.print(num.toString(ant)); c = scan.nextInt(); ant++; // if()若是正確,輸出恭喜答對,d++。不然輸出正確答案。 lastexpression= bee.transit(num.toString()); if(ben.calculator(lastexpression).equals(String.valueOf(c))) {System.out.println("恭喜答對"); e++;} else System.out.println("很遺憾,答錯了"+"正確答案是"+ben.calculator(lastexpression)); } h=(double)b; i=(double)e; f=i/h; luna= fmt.format(f); abc= Double.valueOf(luna); System.out.println("正確率是"+fmt1.format(abc)); System.out.println();//給題目換行 break; case 3: for (int x = 0; x < b; x++) { num.level3(); System.out.print(num.toString(ant)); c = scan.nextInt(); ant++; // if()若是正確,輸出恭喜答對,d++。不然輸出正確答案。 lastexpression= bee.transit(num.toString()); if (ben.calculator(lastexpression).equals(String.valueOf(c))) {System.out.println("恭喜答對"); e++;} else System.out.println("很遺憾,答錯了"+"正確答案是"+ben.calculator(lastexpression)); } h=(double)b; i=(double)e; f=i/h; luna= fmt.format(f); abc= Double.valueOf(luna); System.out.println("正確率是"+fmt1.format(abc)); System.out.println();//給題目換行 break; case 4: for (int x = 0; x < b; x++) { num.level4(); System.out.print(num.toString(ant)); c1 = scan.next(); ant++; // if()若是正確,輸出恭喜答對,d++。不然輸出正確答案。 lastexpression= bee.transit(num.toString()); if (ben.calculator(lastexpression).equals(String.valueOf(c1))) {System.out.println("恭喜答對"); e++;} else System.out.println("很遺憾,答錯了"+"正確答案是"+ben.calculator(lastexpression)); } h=(double)b; i=(double)e; f=i/h; luna= fmt.format(f); abc= Double.valueOf(luna); System.out.println("正確率是"+fmt1.format(abc)); System.out.println();//給題目換行 break; default: System.out.println("請檢查您的輸入.你輸入的結果超出範圍了."); } System.out.println("要繼續作題嗎?(y/n)?"); another = scan.next(); } while (another.equalsIgnoreCase("y")); System.out.println(); } }
PSP2.1 | Personal Software Process Stages | 預估耗時(分鐘) | 實際耗時(分鐘) |
---|---|---|---|
Planning | 計劃 | 60 | 65 |
Estimate | 估計這個任務須要多少時間 | 3 | 2 |
Development | 開發 | 2000 | 3000 |
Analysis | 需求分析 (包括學習新技術) | 350 | 300 |
Coding Standard | 代碼規範 (爲目前的開發制定合適的規範) | 60 | 10 |
Design UML | 設計項目UML類圖 | 60 | 60 |
Coding | 具體編碼 | 1500 | 2000 |
Code Review | 代碼複審 | 30 | 30 |
Test | 測試(自我測試,修改代碼,提交修改) | 300 | 300 |
Size Measurement | 計算工做量(實際時間 ) | 2 | 2 |
Postmortem & Process Improvement Plan | 過後總結, 並提出過程改進計劃 | 30 | 10 |
合計 | 4395 | 5229 |