PSP:
小学生口算题卡 |
实际花费时间 |
估计花费时间 |
计划 |
12 |
15 |
明确需求和其他相关因素,估计每个阶段的时间成本 |
12 |
11 |
开发 |
69 |
74 |
|
5 |
5 |
|
4 |
6 |
|
4 |
6 |
|
3 |
3 |
|
9 |
9 |
|
27 |
21 |
|
5 |
9 |
|
12 |
15 |
报告 |
10 |
6 |
|
5 |
2 |
|
3 |
3 |
|
2 |
1 |
计划:
10道随机生成的计算题
需求分析:
显示题目
输入结果
对比结果
显示结果是否正确
具体设计:
随机生成计算题(10道)
计算时间
计算成绩
同时将不符合一年级的计算题抛出
具体实现:
package entity;
public interface Jjcc {
//加
public int jia(int a,int b);
//减
public int jian(int a,int b);
//乘
public int cheng(int a,int b);
//除
public int chu(int a,int b);
}
package entity;
public class JjccImp implements Jjcc {
@Override
public int jia(int a, int b) {
// TODO Auto-generated method stub
return a+b;
}
@Override
public int jian(int a, int b) {
// TODO Auto-generated method stub
return a-b;
}
@Override
public int cheng(int a, int b) {
// TODO Auto-generated method stub
return a*b;
}
@Override
public int chu(int a, int b) {
// TODO Auto-generated method stub
return a/b;
}
}
public class FourComputer {
// 用于计算的两个随机数
private int a1;
private int a2;
// a4代表除数,直接将0过滤掉
private int a4;
// 通过设置1,2,3,4对应+,-,*,/
private int a3;
// 计算时间,相减即可
long time;
long time2;
// 成绩
int score;
@Test
public void ss() {
// 加减乘除
JjccImp jjcc = new JjccImp();
// 开始时间
time = System.currentTimeMillis();
// 10个算术题
for (int i = 0; i < 10; i++) {
System.out.print("第" + (i + 1) + "题: ");
// 10以内的随机数,使用util.Random即可
a1 = new Random().nextInt(10);
a2 = new Random().nextInt(10);
// 1。。10以内
a4 = new Random().nextInt(9) + 1;
a3 = new Random().nextInt(4) + 1;
// 输入结果
Scanner scanner = new Scanner(System.in);
switch (a3) {
case 1:
System.out.println(a1 + "+" + a2);
System.out.print("请输入结果: ");
int s = scanner.nextInt();
if (jjcc.jia(a1, a2) == s) {
score = score + 10;
System.out.println("回答正确");
break;
} else {
System.out.println("回答错误");
}
break;
case 2:
System.out.println(a1 + "-" + a2);
System.out.print("请输入结果: ");
if (a1 > a2) {
int s1 = scanner.nextInt();
// 当a1>a2,否则直接将题目抛出,并将循环次数加1次以补齐10到算术题
if (jjcc.jian(a1, a2) == s1) {
score = score + 10;
System.out.println("回答正确");
} else {
System.out.println("回答错误");
}
} else {
System.out.println("题目超纲");
i = i - 1;
}
break;
case 3:
System.out.println(a1 + "*" + a2);
System.out.println("请输入结果: ");
int s2 = scanner.nextInt();
if (jjcc.cheng(a1, a2) == s2) {
score = score + 10;
System.out.println("回答正确");
break;
} else {
System.out.println("回答错误");
}
break;
case 4:
System.out.println(a1 + "/" + a4);
System.out.println("请输入结果: ");
if ((a1 % a4) == 0) {
double s3 = scanner.nextInt();
if (jjcc.chu(a1, a4) == s3) {
score = score + 10;
System.out.println("回答正确");
} else {
System.out.println("回答错误");
}
} else {
System.out.println("题目超纲");
i = i - 1;
}
break;
}
// 结束时间
}
time2 = System.currentTimeMillis();
System.out.println("总共用时" + ((time2 - time) / 1000) + "s");
System.out.println("成绩是" + score + "分");
}
}
运行结果: