一、隨機生成題目html
二、題目運算(判題)java
三、題目合法性判斷git
四、擴展需求編程
一、設計一個IntNumber
類,用來實現整數的四則運算
二、設計一個Judgement
類,用來判斷用戶輸入與實際計算值是否相等,並統計正確的次數
三、設計一個Fraction
類,用來實現真分數的四則運算
四、設計主類,生成隨機數,生成題目,並判斷正確率
五、設計測試類,測試整數類與分數類的四則運算
六、設計一個MultiLanguage
類,用來實現多語言的擴展
dom
import java.text.NumberFormat; import java.util.*; public class Calculate { public static void main(String[] args) { NumberFormat number = NumberFormat.getPercentInstance(); Random ran = new Random(); Scanner scan = new Scanner(System.in); while (true) { System.out.print("請輸入要生成的題目數量:"); int A = scan.nextInt(); for (int i = 0; i < A; i++) { int B = ran.nextInt(2); int C = ran.nextInt(4); IntNumber in1 = IntNumber.obj(); IntNumber in2 = IntNumber.obj(); Fraction score1 = Fraction.obj(); Fraction score2 = Fraction.obj(); if (B == 0) {//隨機生成整數的計算題目 switch (C) { case 0: int num = in1.add(in2); String num1 = "" + num; int n = scan.nextInt(); Judgement.judge(n == num, num1); break; case 1: num = in1.subtract(in2); num1 = "" + num; n = scan.nextInt(); Judgement.judge(n == num, num1); break; case 2: num = in1.multiply(in2); num1 = "" + num; n = scan.nextInt(); Judgement.judge(n == num, num1); break; case 3: num1 = in1.divide(score1); String Q = scan.next(); Judgement.judge(Q.equals(num1), num1); break; } } else {//隨機生成真分數的計算題目 switch (C) { case 0: Fraction num2 = score1.add(score2); String num1 = num2.toString(); String s = scan.next(); Judgement.judge(s.equals(num1), num1); break; case 1: num2 = score1.subtract(score2); num1 = num2.toString(); s = scan.next(); Judgement.judge(s.equals(num1), num1); break; case 2: num2 = score1.multiply(score2); num1 = num2.toString(); s = scan.next(); Judgement.judge(s.equals(num1), num1); break; case 3: num2 = score1.divide(score2); num1 = num2.toString(); s = scan.next(); Judgement.judge(s.equals(num1), num1); break; } } } System.out.println("你答對的題目總數:" + Judgement.getTrues()); double T = (double) Judgement.getTrues() / A;//計算正確率 System.out.println("正確率爲:" + number.format(T)); System.out.println("是否繼續生成題目?(y/n):" );//屢次生成題目,直到用戶選擇退出 String s1 = scan.next(); if (s1.equalsIgnoreCase("n")){ break; } } } }
import javax.lang.model.element.NestingKind; import java.util.*; public class MultiLanguage { private Integer option; private String language; public String getLanguage() { return language; } public MultiLanguage(){ setLanguage(); } private void setLanguage(){ System.out.printf("Please choose a language and type it! \n" + "請你選擇一種語言而且輸入對應的縮寫!\n" + "請妳選擇壹種語言並且輸入對應的縮寫!\n" + "EN/ZH_CN/ZH_HK"); HashMap<String,Integer> lanList = new HashMap<String,Integer>(); lanList.put("EN",0); lanList.put("ZH_CN",1); lanList.put("ZH_HK",2); Scanner sc = new Scanner(System.in); language = sc.nextLine(); this.option = lanList.get(language); } public void output(String type){ String[] output_1 = {"Ready......Go!","預備,開始!","準備,開始!"}, output_2 = {"YOUR ANSWER : ","你的回答是:","妳的回答是:"}, output_3 = {"KEY :","答案爲:","答案爲:"}, output_4 = {"------------ERROR------------","------------錯誤------------","------------錯誤------------"}, output_5 = {"------------ACCESS-----------","------------經過-------------","------------通過------------"}, output_6 = {"Your Accuracy:","您的正確率:","您的正確率:"}; if(type.equals("st"))System.out.printf(output_1[option] + "\n"); else if(type.equals("ans"))System.out.printf(output_2[option]); else if(type.equals("key"))System.out.printf(output_3[option]); else if(type.equals("err"))System.out.printf(output_4[option] + "\n"); else if(type.equals("acc"))System.out.printf(output_5[option] + "\n"); else if (type.equals ( "accuracy") )System.out.printf(output_6[option] ); } }
IntNumber類的方法測試
ide
Fraction類的方法測試
單元測試
junit
,單擊JunitGenerator V2.0
,單擊綠色的Install
按鈕安裝。但我沒有搜到JunitGenerator V2.0
。問題1解決方案:經過百度搜索,在網上查找並下載:到本地,而後找到插件所在位置,再install plugin from disk
,。學習
Random random = new Random() random.nextInt()
並結合switch語句,成功實現生成隨機數和題目測試
PSP | Personal Software Process Stages) | 預估耗時(分鐘) | 實際耗時(分鐘) |
---|---|---|---|
Planning | 計劃 | 30 | 70 |
Estimate | 估計這個任務須要多少時間 | 360 | 500 |
Development | 開發 | 60 | 100 |
Analysis | 需求分析 (包括學習新技術) | 30 | 40 |
Design Spec | 生成設計文檔 | 30 | 35 |
Design Review | 設計複審 (和同事審覈設計文檔) | 25 | 20 |
Coding Standard | 代碼規範 (爲目前的開發制定合適的規範) | 15 | 30 |
Design | 具體設計 | 60 | 75 |
Coding | 具體編碼 | 180 | 255 |
Code Review | 代碼複審 | 30 | 25 |
Test | 測試(自我測試,修改代碼,提交修改) | 150 | 135 |
Reporting | 報告 | 60 | 90 |
Test Report | 測試報告 | 20 | 25 |
Size Measurement | 計算工做量 | 10 | 5 |
Postmortem & Process Improvement Plan | 過後總結, 並提出過程改進計劃 | 60 | 80 |
合計 | 1120 | 1485 |