java 隨機出題四則運算


作業要求來源於:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2186

我的github地址:https://github.com/kdaysl/fshost/blob/master/mar.java

 

一、需求分析
     
具體要求:任何編程語言都可以,命令行程序接受一個數字輸入,然后輸出相應數目的四則運算題目和答案。例如輸入數字是 30, 那就輸出 30 道題目和答案。 運算式子必須至少有兩個運算符,運算數字是在 100 之內的正整數,答案不能是負數。並且要求能處理用戶的輸入,並判斷對錯,打分統計。

 

二、功能設計

  1.  輸出相應數目的四則運算(加減乘除)題目及答案;

  2. 隨機產生具有三個操作數和兩個運算符的四則運算;

  3. 四則運算的答案不能為負數,如果為負數則重新輸入該道題目;

  4. 對用戶的輸入答案進行判斷,正確則加分,錯誤則不加分,並予以提示。滿分為100分;

  5. 輸出用戶的總分數。

 ____________________________________________________________________________________________________________________________________________________________________

三、詳細設計

  1. 由於時間問題使用嵌套switch來完成多步計算

   1.1隨機產生前兩個數字並和第一個運算符:

 
front = random.nextInt(100);
back = random.nextInt(100);
symbol = random.nextInt(4);
 

  2.1嵌套switch-外:

 
switch (Symbol) {
case 0:
{
sSymbol = random.nextInt(4);
end = random.nextInt(100);
            switch (ssymbol){
...
}

case 1:
{
while (front < back) {
front = random.nextInt(100);
back = random.nextInt(100);
}
sSymbol = random.nextInt(4);
end = random.nextInt(100);
            switch (ssymbol){
...
}

break;
}
case 2:
{
sSymbol = random.nextInt(4);
end = random.nextInt(100);
            switch (ssymbol){
...
}
            break;
}
case 3:
{
if (back == 0) {
back = random.nextInt(99) + 1;
}
while (front % back != 0) {
front = random.nextInt(100);
back = random.nextInt(99) + 1;
}
sSymbol = random.nextInt(4);
end = random.nextInt(100);
switch (ssymbol){
...
}
break;
}
}
}
 

  2.2switch嵌套-里,

  

 
switch (sSymbol){
case 0:{
...
inResult = input.nextInt();
corResult = front / back +end;
if (inResult == corResult)
correct++;
else {
...
}
break;
}
case 1:{
...
inResult = input.nextInt();
corResult = front / back -end;
if (inResult == corResult)
correct++;
else {
...
}
break;
}
case 2:{
...
inResult = input.nextInt();
corResult = front / back -end;
if (inResult == corResult)
correct++;
else {
...
}
break;
}
case 3:{
if (end == 0) {
end = random.nextInt(100);
}
while ((front + back)% end != 0) {
front = random.nextInt(100);
back = random.nextInt(100);
end = random.nextInt(99) + 1;
}
...
inResult = input.nextInt();
corResult = front / back / end;
if (inResult == corResult)
correct++;
else {
...
}
break;
}
}
 

  31.錯題錄入數組

            errorSymbol[j] = ( front + "/" + back +"/"+end+ "="+corResult);
            errorId[k] = i + 1; 

  3.2用戶輸入答案對比

Scanner input = new Scanner(System.in);

inResult = input.nextInt();
corResult...
if (inResult == corResult){
...}

  

 

 

 

     

四、過程耗時估計統計表

 

PSP2.1

Personal Software Process Stages

Time Senior Studenh

Timeh

Planning

計划

0.1

0.1

Estimate

估計這個任務需要多少時間

1

1

Development

開發

2

3

Analysis

需求分析

0.1

0

Design Spec

生成設計文檔

0

0

Design Review

設計復審

0

0

Coding Standard

代碼規范

0

0

Design

具體設計

1

1.5

Coding

具體編碼

2

3

Code Review

代碼復審

0

0

Test

測試(自我測試,修改代碼,提交修改)

1

1

Reporting

報告

0

0

 

測試報告

0

0

 

計算工作量

2

3

 

並提出過程修改計划

0

0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM