Write code for a 3rd Grade math tutor program that provides simple addition questions. Use only numbers in the range 0 to 100 inclusive in the math problems. No number should exceed 100 in the questions or answers.

Respuesta :

Answer:

Here is the JAVA program:

import java.util.Random;   //to generate random numbers

import java.util.Scanner;  //to accept input from user

public class Main {  //class name

   public static void main(String[] args) { //start of main method

      int score = 0;  //to store the number of correct answers

Random rand = new Random();  //generates random numbers

int answer;  //to store the answers given by student

       do {  //to keep asking addition questions

            int number1 = rand.nextInt(101);  //generate random number from 0 to 100 for operand 1

       int number2 = rand.nextInt(101);  //generate random number from 0 to 100 for operand 2          

           Scanner input = new Scanner(System.in);  //to read input from user

           System.out.print("What is " + number1 + " + " + number2 + " ? ");  //asks addition question

            answer = input.nextInt();  //reads the answer from user(student)

           if ((number1 + number2) == answer)  //if user answer of addition of two numbers is correct            

               score = score + 1;     //adds 1 to the score each time the answer to the addition question is correct

                 }while(answer<=100);  //keeps asking question until the answer number exceeds 100

               System.out.println("Total score is: " + score);  }}//displays the total score of student

           

Explanation:

The above program basically asks addition questions from user. Each addition question has two random numbers and the answer is given by user. At each right answer, the variable score is incremented by 1 in order to store the number of correct answers by user. If the answer to any addition question exceeds 100 then the loop breaks and program stops and the questions answered before that question is considered only.

Another way to do this is to ask 10 addition questions by using random numbers as operands and only that answer is considered which does not exceed 100. Next the if condition checks if the answer to the addition is correct. If this condition evaluates to true then the if condition inside this if condition checks that the value of answer does not exceed 100. If this inner if condition evaluate to true only then the score is incremented to 1 otherwise not and the program displays a message. Here is that program:

import java.util.Random;  

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       int score = 0;

Random rand = new Random();  

       for (int i = 0; i < 11; i++) {

            int number1 = rand.nextInt(101);  

       int number2 = rand.nextInt(101);            

           Scanner input = new Scanner(System.in);

           System.out.print("What is " + number1 + " + " + number2 + " ? ");

           int answer = input.nextInt();  

           if ((number1 + number2) == answer)  

           { if (answer<=100)

              { score = score + 1;}

               else

               {System.out.print("Answer should not be greater than 100 \n");}         }   }

               System.out.println("Total score is: " + score);  }}

The screenshot of both program outputs is attached.

Ver imagen mahamnasir
Ver imagen mahamnasir

Answer:how the hell do u even do that the guy made one kudos to him

Explanation:I didn’t realize I was writing this here I meant to my friend