2021-09-19

大三上软件工程作业一:
编程作业
为小学低年级的同学设计一个答题软件,随机产生20个整数(100以内)加减运算题,并能判分。进行结对交叉测试。提交设计思想,功能说明,源代码,可运行程序及他人测试的报告
正确版:
import java.util.Random;
import java.util.Scanner;
public class sumANDsub {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	int e=0, r=0;
	System.out.println("欢迎来到加减测试");
	System.out.println("做题前请认真读题,祝您考试顺利!");
	Random r1 = new Random();

/* for(int i=0;i<20;i++) {
int m,n;
int a,b,c;
m=r1.nextInt()%10;
n=m%4;
*/
for(int i=0;i<10;i++) {
int m,n;
int a,b,c;
m=r1.nextInt(10);
n=m%2;
switch(n) {
case 0:
a=new Random().nextInt((int)Math.pow(10,2))+1;
b=new Random().nextInt((int)Math.pow(10, 2))+1;
System.out.println(a + “+” + “” + b + “=?”);
//下面两行表示输入的数只能为整数
Scanner x1 =new Scanner(System.in);
c=x1.nextInt();
if(c!=a+b)
{
e++;
System.out.println(“回答错误!”);
}
else
{
r++;
System.out.println(“回答正确!”);
}
break;
case 1:
a = new Random().nextInt((int) Math.pow(10, 2)) + 1;
b = new Random().nextInt((int) Math.pow(10, 2)) + 1;
if(a<b)
{
int temp;
temp=b;
b=a;
a=temp;
}
System.out.println(a + “-” + " " + b + " =?");
Scanner x2 = new Scanner(System.in);
c = x2.nextInt();
if (c != a - b)
{
e++;
System.out.println(“回答错误!加油”);
}
else
{
r++;
System.out.println(“回答正确!很棒”);
}
break;
}
}
System.out.println(“考试已结束!”);
System.out.println(“您一共做了:” + (r + e) + “道题目,其中正确的有” + r + “道,错误的有” + e + “道!”);
}
}
有误版(可成功编译)

package software;
import java.util.Random;import java.util.Scanner;public class sumANDsub { public static void main(String[] args) { // TODO Auto-generated method stub int e=0, r=0; System.out.println(“欢迎来到加减测试”); System.out.println(“做题前请认真读题,祝您考试顺利!”); Random r1 = new Random();/* for(int i=0;i<20;i++) { int m,n; int a,b,c; m=r1.nextInt()%10; n=m%4; */ for(int i=0;i<20;i++) { int m,n; int a,b,c; m=r1.nextInt()%10; n=m%2; switch(n) { case 0: a=new Random().nextInt((int)Math.pow(10,2))+1; b=new Random().nextInt((int)Math.pow(10, 2))+1; System.out.println(a + “+” + “” + b + “=?”); Scanner x1 =new Scanner(System.in); c=x1.nextInt(); if(c!=a+b) { e++; System.out.println(“回答错误!”); } else { r++; System.out.println(“回答正确!”); } break; case 1: a = new Random().nextInt((int) Math.pow(10, 2)) + 1; b = new Random().nextInt((int) Math.pow(10, 2)) + 1; if(a<b) { int temp; temp=b; b=a; a=temp; } System.out.println(a + “-” + " " + b + " =?"); Scanner x2 = new Scanner(System.in); c = x2.nextInt(); if (c != a - b) { e++; System.out.println(“回答错误!加油”); } else { r++; System.out.println(“回答正确!很棒”); } break; } } System.out.println(“考试已结束!”); System.out.println(“您一共做了:” + (r + e) + “道题目,其中正确的有” + r + “道,错误的有” + e + “道!”); }}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Narcissus努力学习不秃头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值