Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:01:31+00:00 2026-05-31T06:01:31+00:00

Any help would be greatly appreciated. I’m trying to implement a simple maths game.

  • 0

Any help would be greatly appreciated. I’m trying to implement a simple maths game. I’ve gotten as far as generating random questions and being able to validate answers, but I want to limit the game to ten questions and to display the users score after the final question. I’m a novice programmer and from what I understand I will require some form of loop. Any code examples or general help/advice would be fantastic, thanks.

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

    checkAnswer();
    getQuestion();


    break;

case R.id.keypad_1:

    editText.append(String.valueOf(v.getTag()));

    break;


case R.id.keypad_2:

    editText.append(String.valueOf(v.getTag()));

    break;



case R.id.keypad_3:

    editText.append(String.valueOf(v.getTag()));

    break;

case R.id.keypad_4:

editText.append(String.valueOf(v.getTag()));

break;

case R.id.keypad_5:

editText.append(String.valueOf(v.getTag()));

break;

case R.id.keypad_6:

editText.append(String.valueOf(v.getTag()));

break;

case R.id.keypad_7:

editText.append(String.valueOf(v.getTag()));

break;

case R.id.keypad_8:

editText.append(String.valueOf(v.getTag()));

break;

case R.id.keypad_9:

editText.append(String.valueOf(v.getTag()));

break;
case R.id.keypad_0:

editText.append(String.valueOf(v.getTag()));

break;
case R.id.keypad_delete:

    if (editText.getText().length() > 0) {
        editText.getText().delete(editText.getText().length() - 1,
                editText.getText().length());
    }

break;

case R.id.keypad_minus:

editText.append(String.valueOf(v.getTag()));


break;

  } 
}

public void getQuestion(){

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

    int i1 = Min + (int)(Math.random() * ((Max - Min) + 1));
    for (int i = 0; i < 10; i++) {
    if(i1 == 1){
    question = (random1 + "+" + random2);
    correctAnswer = random1 + random2;
    editTextEquation.setText(question);
    }
    if(i1 == 2){
    question = (random1 + "-" +random2);
    correctAnswer = random1 - random2;
    editTextEquation.setText(question);

    }
    if(i1 == 3){
    question = random1 + "/" +random2;
    correctAnswer = random1 / random2;
    editTextEquation.setText(question);

    }
    if(i1 == 4){
    question = (random1 + "*" +random2);
    correctAnswer = random1 * random2;
    editTextEquation.setText(question);


    }
    }

    }




    public void checkAnswer(){
       int mm = 0;
        //answer = editText.getText().toString();
        mm = Integer.parseInt(editText.getText().toString());

        if (mm == correctAnswer){

          score++;
        scoredisplay.setText("" + score);


    }
        else {

        score--;
        scoredisplay.setText("" + score);
    }




 }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:01:33+00:00Added an answer on May 31, 2026 at 6:01 am

    you might not need a loop the way you built it.

    this.counter = 10;
    
    ...
    
    case R.id.keypad_hash:
      checkAnswer();
      this.counter--;
      if( this.counter > 0 ){
        getQuestion();
      } else {
        scoreText.setText(score);
      }
      break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get this code working, any help would be greatly appreciated. <mx:DataGrid
I am struggling to carry out the following. Any help would be greatly appreciated.
Any help here would be greatly appreciated. I have this table hospital Nurse |
Any help would be appreciated, I'm trying to convert the code below to C#,
My client is starting to get antsy....so any help would be greatly appreciated. I
I am new to RoR, any help would be greatly appreciated :) I have
For starters, any help would be greatly appreciated! I have created a numerical keypad
this is my first post, any help would be greatly appreciated. I have to
Can't get this to work for some reason. Any help would be greatly appreciated.
I'm having problems with the Channel API - any help would be greatly appreciated.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.