Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Join our Q&A platform to get precise answers from experts in diverse fields and enhance your understanding. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

Write a program that teaches arithmetic to a young child. The program tests addition and subtraction. In level 1, it tests only addition of numbers less than 10 whose sum is less than 10. In level 2, it tests addition of arbitrary one digit numbers (which means that the sum could be more than 10). In level 3, it tests subtractions of one digit numbers with a non-negative difference. Generate random numbers for each of the levels based on its requirements, and get players answers as their response. Verify if the user entered the correct answer. The player will start at level 1, and gets up to two tries per problem. Advance from one level to the next when the player has achieved a score of five points (one point per successful answering the question).

Sagot :

Answer:

Explanation:

The following program is written in Java and creates three levels with the different set of randomly generated arithmetic problems. As the player goes getting more points they advance every 5 points to the next level.

import java.util.Random;

import java.util.Scanner;

class Main {

   private static Random random = new Random();

   private static Scanner in = new Scanner(System.in);

   static int points = 0;

   public static void main(String[] args) {

       while (true) {

           System.out.println(points);

           if (points < 5) {

               System.out.println("Starting Level 1");

               levelOne();

           } else if (points < 10) {

               System.out.println("Starting Level 2");

               levelTwo();

           } else if (points < 15) {

               System.out.println("Starting Level 3");

               levelThree();

           }

       }

   }

   public static boolean levelOne() {

       int numberOne = random.nextInt(10);

       int numberTwo = random.nextInt((10 - numberOne));

       int answer = numberOne + numberTwo;

       int count = 0;

       while (points < 5 && count < 2) {

           System.out.println("What is " + numberOne + " + " + numberTwo + "?: ");

           int userChoice = in.nextInt();

           if (userChoice == answer) {

               points += 1;

               levelOne();

           } else {

               count += 1;

           }

       }

       return false;

   }

   public static boolean levelTwo() {

       int numberOne = random.nextInt(10);

       int numberTwo = random.nextInt(10);

       int answer = numberOne + numberTwo;

       int count = 0;

       while (points < 10 && count < 2) {

           System.out.println("What is " + numberOne + " + " + numberTwo + "?: ");

           int userChoice = in.nextInt();

           if (userChoice == answer) {

               points += 1;

               levelTwo();

           } else {

               count += 1;

           }

       }

       return false;

   }

   public static boolean levelThree() {

       int numberOne = random.nextInt(10);

       int numberTwo = random.nextInt(10);

       int answer = numberOne - numberTwo;

       int count = 0;

       if (answer <= 0) {

           levelThree();

       }

       while (points < 15 && count < 2) {

           System.out.println("What is " + numberOne + " - " + numberTwo + "?: ");

           int userChoice = in.nextInt();

           if (userChoice == answer) {

               points += 1;

               levelThree();

           } else {

               count += 1;

           }

       }

       return false;

   }

}

View image sandlee09