package calculator;
public class Question {
int number;
public int result[]=new int[100];
public void question(int a){
number=a;
for(int i=1;i<=number;i++){
int x=(int)(Math.random()*10);
int y=(int)(Math.random()*10);
System.out.println(x+"+"+y+"= ");
result[i]=x+y;
}
}
public int getNumber(){
return number;
}
public int getResult(int i){
return result[i];
}
}
package calculator;
import java.util.Scanner;
public class Answer extends Question{
public int answer[]=new int [100];
int point=0;
public void result(){
Question r=new Question();
Scanner a=new Scanner(System.in);
for(int i=1;i<r.getNumber();i++)
answer[i]=a.nextInt();
for(int i=1;i<number;i++)
if(answer[i]==r.getResult(i)){
System.out.println("这个结果是对的");
point++;
}
else
System.out.println("这个结果是错的");
a.close();
}
public int getResult(){
return point;
}
}
package calculator;
import java.util.Scanner;
public class Maincalculator {
public static void main(String[] args) {
System.out.println("今天你想在学习的海洋中翱翔几道题呢?");
Scanner input=new Scanner(System.in);
int sea=input.nextInt();
input.close();
System.out.println("哈哈,你居然只做"+sea+"道,你还差得远呢!不过还是如你所愿");
Question ques=new Question();
ques.question(sea);
System.out.println("现在请输入你对应的答案!!!");
Answer ans=new Answer();
ans.result();
int score=ans.getResult();
System.out.println("你的分数是"+score);
}
}
添加回答
举报
0/150
提交
取消