java实现加减乘除运算符随机生成十道题并判断对错_java 随机出题四则运算

我的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 Studen(h)

Time(h)

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

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值