一個命令行程序實現:java
統計正確率git
import java.util.Scanner; public class question { public static void main(String[] args) { int k; int total,answer=0; int answer2; int count=0; System.out.println("請輸入你須要練習的題目數:"); Scanner input=new Scanner(System.in ); total=input.nextInt(); question question=new question(); for(int n=0;n<total;n++) { int i=(int)(Math.random()*100); int j=(int)(Math.random()*100); switch((int)(Math.random()*4)) { case 0: System.out.println(i+"+"+j+"="); answer=i+j; break; case 1: if(i<j) { int temp=i; i=j; j=temp; } System.out.println(i+"-"+j+"="); answer=i-j; break; case 2: System.out.println(i+"*"+j+"="); answer=i*j; break; case 3: while(j==0) j= (int)(Math.random()*100); System.out.println(i+"/"+j+"="); answer=i/j; break; } Scanner input2=new Scanner(System.in ); answer2=input2.nextInt(); if(answer2==answer){ System.out.println("正確!"); count++; } else{ System.out.println("錯誤!"); } } float cent=(float)count/(float)total; System.out.println("正確率爲"+cent); } }
碼雲地址編程
PSP2.1 | Personal Software Process Stages | 預估耗時(分鐘) | 實際耗時(分鐘) |
---|---|---|---|
· Test | · 測試(自我測試,修改代碼,提交修改) | 20min | 25min |
Planning | 計劃 | 15min | 10min |
· Estimate | · 估計這個任務須要多少時間 | 240min | 260min |
Development | 開發 | 40min | 35min |
· Analysis | · 需求分析 (包括學習新技術) | 15min | 35min |
· Coding Standard | · 代碼規範 (爲目前的開發制定合適的規範) | 10min | 15min |
· Coding | · 具體編碼 | 2h | 100min |
· Code Review | · 代碼複審 | 30min | 40min |