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

posted @ 2018-10-15 00:52  prous  阅读(1507)  评论(2编辑  收藏  举报