简体   繁体   English

简单的数学游戏

[英]Simple maths game

I've tried a few solutions, but not having much luck. 我尝试了一些解决方案,但运气不佳。 If anyone with some spare time can have a look at my code and maybe point me in the right direction, it would be appreciated. 如果有空余时间的人可以看一下我的代码,甚至可以为我指出正确的方向,将不胜感激。

Here I have a button that's calling these methods. 在这里,我有一个调用这些方法的按钮。 One to check the answer and one to get another question which will display in the textview. 一个检查答案,另一个得到另一个问题,该问题将显示在文本视图中。 Ideally I want a sequence of ten random questions and for the user to be able to guess each one via the edittext and if they get one right a score counter is incremented each time. 理想情况下,我想要一个由10个随机问题组成的序列,并且用户可以通过edittext猜出每个问题,如果它们正确无误,则每次都会增加一个计分计数器。

  @Override
public void onClick(View v){
switch(v.getId()){
case R.id.keypad_hash:

    checkAnswer(editTextEquation.getText().toString(), editText.getText().toString());

    editTextEquation.setText(getQuestion());

    break;

I'm having difficulty working out how to code the rest 我很难弄清楚其余的代码

 String getQuestion(){

    random1 = (int)(Math.random()*100);
    random2 = (int)(Math.random()*10);

    int i1 = Min + (int)(Math.random() * ((Max - Min) + 1));

    if(i1 == 1){
    question = String.valueOf(random1 + "+" + random2);

    }
    if(i1 == 2){
    question = String.valueOf(random1 + "-" +random2);


    }
    if(i1 == 3){
    question = String.valueOf(random1 + "/" +random2);


    }
    if(i1 == 4){
    question = String.valueOf(random1 + "*" +random2);


    }

    return question;

}

boolean checkAnswer(String question, String answer){


    return true;


}

just add something like 只需添加类似

double correctAnswer;
(...)
if(i1 == 4){
    question = String.valueOf(random1 + "*" +random2);
    correctAnswer = random1*random2
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM