一道JAVA作业题求教求设计程序!面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答。功能要求:(1)电脑随机出10道题,每题10分,程序结束时显示学生得分;(2)
面向小学1~2年级学生,随机选择两个整数和加减法形成算式要求学生解答。
功能要求:
(1)电脑随机出10道题,每题10分,程序结束时显示学生得分;
(2)确保算式没有超出1~2年级的水平,只允许进行50以内的加减法,不允许两数之和或之差超出0~50的范围,负数更是不允许的;
(3)每道题学生有三次机会输入答案,当学生输入错误答案时,提醒学生重新输入,如果三次机会结束则输出正确答案;
(4)对于每道题,学生第一次输入正确答案得10分,第二次输入正确答案得7分,第三次输入正确答案得5分,否则不得分;
(5)总成绩90以上显示“SMART”
,80-90显示“GOOD”,70-80显示“OK”,60-70显示“PASS”,60以下“TRY AGAIN
亲测可运行。
import java.io.*;
public class Pratices {
public static void main(String[] args) {
new Pratices().list_Pratices();
}
//产生随机数
public int random_Num(int range) {
return (int) (Math.random() * range);
}
public void list_Pratices() {
int num_1, num_2, temp;
int type = random_Num(2);
int count = 1;
int score = 0;
int right = 0;
int wrongtimes = 0;
while (count <= 10) {
type = random_Num(2);
num_1 = random_Num(20); //可以修改这里来更改范围
num_2 = random_Num(30); //同上 现在是一个数20 一个数30以内的随机数
wrongtimes = 0;
if (type == 0) {
System.out.print("(" + count + ") " + num_1 + " + " + num_2
+ " = ");
} else if(type == 1){
if ((num_1 < num_2)) {
temp = num_1;
num_1 = num_2;
num_2 = temp;
}
System.out.print("(" + count + ") " + num_1 + " - " + num_2
+ " = ");
}
int answer = this.getAnswer(count);
boolean flag = check(num_1, num_2, type, answer, count);
if (flag) {
right++;
System.out.println("回答正确");
score += this.getScore(wrongtimes);
} else {
while (wrongtimes < 2) {
wrongtimes++;
System.out.println("回答错误 " + wrongtimes + " 次");
answer = this.getAnswer(count);
flag = check(num_1, num_2, type, answer, count);
if (flag) {
score += this.getScore(wrongtimes);
right++;
wrongtimes = 0;
break;
}
}
if (wrongtimes == 3)
System.out.println("回答错误 ");
else
System.out.println("回答正确");
}
count++;
}
System.out.println("回答正确 : " + right);
System.out.println("回答错误: " + (10 - right));
System.out.println("获得分数: " + score);
System.out.println(getDegree(score));
}
public boolean check(int num_1, int num_2, int type, int my_Answer,
int count) {
int answer = 0;
if (type == 1) {
answer = num_1 - num_2;
} else if (type == 0) {
answer = num_1 + num_2;
}
return my_Answer == answer;
}
public int getAnswer(int count) {
int my_Answer = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
my_Answer = Integer.parseInt(br.readLine());
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
System.out.println("输入有误");
return 0;
} finally {
if (count >= 10 && (br != null)) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
br = null;
}
}
return my_Answer;
}
public int getScore(int wrongtimes) {
if (wrongtimes == 0) {
return 10;
} else if (wrongtimes == 1) {
return 7;
} else if (wrongtimes == 2) {
return 5;
} else
return 0;
}
public String getDegree(int score) {
if (score > 90)
return "SMART";
else if (score > 80)
return "GOOD";
else if (score > 70)
return "OK";
else if (score > 60)
return "PASS";
else
return "TRY AGAIN";
}
}
A、1道题10分;B、3道题50分;C、5道题100分;A、10道题200分如果题目难易程度一样, 2020-06-10 …
高三数学问题,在线等!详细回答,有过程拜托~~~~~~若f(x)=x^2-2x+2及f(a+1)= 2020-06-10 …
"实数根号下a的平方的平方根为正负a"这道题对吗 2020-06-13 …
下列加线成语运用不正确的一项是()A.这道题在老师指导之后,我忽然恍然大悟.B.回想此前和此后截然 2020-06-17 …
下列句子中,加点的成语使用不恰当的一项是()A.这道题经老师一讲,他茅塞顿开,马上找到了答案.B. 2020-07-03 …
Ioftensaidteacherhaveveryeasylife.A./;/B./;aC.the 2020-07-13 …
高数第五版的21页第5题题中的f^-1()不是f的逆映射吗?这样f:X->Y不就是单射吗?为什么还 2020-07-30 …
非零数a除以一个小数,所得的商一定大于a这道题该打√还是x 2020-12-27 …
初一一元一次方程与代数1.k取何值时,方程9x-3=kx+14有正数解?并求出正数解.2.若方程(x 2020-12-31 …
知道直线L过点P(-5,-4),且在x轴上和y轴上截距相等求直线方程~第二道题已知两点A(-1,-5 2021-01-06 …