Question

Using Java IDE: Write an application that asks elementary students a set of 10 math problems...

Using Java IDE:

Write an application that asks elementary students a set of 10 math problems

● First ask the user for a level and a problem type.

● You need to validate the level and problem type and loop until the user enters a correct one.

● There should be 3 levels. Level 1 operands would have values in the range of 0-9, level 2 operands would have values in the range of 0-99, and level 3 operands would have values in the range of 0-999.

● Each problem will consist of three randomly generated operands.

● There should be 4 problem types. Problem type 1 requires the student to find the sum of the threenumbers, problem type 2 requires the user to find the integer average of the three numbers, problem type 3 requires the user to find the largest of the threenumbers, and problem type 4 requires the user to find the smallest of the three numbers.

● The program should ask the user 10 questions.

● The program should randomly generate the numbers for each problem and display them to the user. Then the program should get the users answer and check that answer.

● The program should provide individual feedback foreach problem. There should be 3 different positive and 3 different negative feedbacks chosen from for each problem.

● After the user finishes their 10 problems, display the number they got right and then query them if they want to play again. If they choose to play again, get a new level and problem type before asking 10 new problems.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

import java.util.Random;
import java.util.Scanner;

public class MathProblemsToStudent {

   public static void main(String[] args) {
       int level, problemType, feedback;
       int a, b, c;
       double answer;
       int numberCorrect = 0;
       String userChoice = "";
       boolean repeat = true;
       Scanner input = new Scanner(System.in);
       Random rand = new Random();
       //run a loop as long as user wishes to continue
       while(repeat)
       {
           //get the level the user wishes to play
           level = getLevel(input);
           //get the problem type
           problemType = getProblemType(input);
           numberCorrect = 0;
           //run a loop for 10 times
           for(int i = 1; i <= 10; i++)
           {
               //generate three random numbers based on level type selected
               //if level is 1 generate 3 numbers between 0-9
               if(level == 1)
               {
                   a = rand.nextInt(10);
                   b = rand.nextInt(10);
                   c = rand.nextInt(10);
               }
               //if level is 1 generate 3 numbers between 0-99
               else if(level == 2)
               {
                   a = rand.nextInt(100);
                   b = rand.nextInt(100);
                   c = rand.nextInt(100);
               }
               //if level is 1 generate 3 numbers between 0-999
               else
               {
                   a = rand.nextInt(1000);
                   b = rand.nextInt(1000);
                   c = rand.nextInt(1000);
               }
               //generate questions based on problem type selected
               if(problemType == 1)
               {
                   //display the question
                   System.out.print("Question " + i + ". " + "What is the sum of " + a + ", " + b + ", " + c + "? ");
                   //get the answer from the user
                   answer = input.nextDouble();
                   //generate a random number for feedback message
                   feedback = rand.nextInt(3);
                   //if answer is correct display feedback and increment count of correct answers
                   if(a + b + c == answer)
                   {
                       printPositiveFeedback(feedback);
                       numberCorrect++;
                   }
                   //else display negative feedback
                   else
                       printNegativeFeedback(feedback);
               }
               else if(problemType == 2)
               {
                   //display the question
                   System.out.print("Question " + i + ". " + "What is the average of " + a + ", " + b + ", " + c + "? ");
                   //get the answer from the user
                   answer = input.nextDouble();
                   //generate a random number for feedback message
                   feedback = rand.nextInt(3);
                   //if answer is correct display feedback and increment count of correct answers
                   if(((int)((a + b + c) / 3)) ==(int)(answer))
                   {
                       printPositiveFeedback(feedback);
                       numberCorrect++;
                   }
                   //else display negative feedback
                   else
                       printNegativeFeedback(feedback);
               }
               else if(problemType == 3)
               {
                   //display the question
                   System.out.print("Question " + i + ". " + "What is the largest of " + a + ", " + b + ", " + c + "? ");
                   //get the answer from the user
                   answer = input.nextDouble();
                   //generate a random number for feedback message
                   feedback = rand.nextInt(3);
                   //find the largest number
                   int largest = a;
                   if(b > largest)
                       largest = b;
                   if(c > largest)
                       largest = c;
                   //if answer is correct display feedback and increment count of correct answers
                   if(largest == answer)
                   {
                       printPositiveFeedback(feedback);
                       numberCorrect++;
                   }
                   //else display negative feedback
                   else
                       printNegativeFeedback(feedback);
               }
               else
               {
                   //display the question
                   System.out.print("Question " + i + ". " + "What is the smallest of " + a + ", " + b + ", " + c + "? ");
                   //get the answer from the user
                   answer = input.nextDouble();
                   //generate a random number for feedback message
                   feedback = rand.nextInt(3);
                   //find the smallest number
                   int smallest = a;
                   if(b < smallest)
                       smallest = b;
                   if(c < smallest)
                       smallest = c;
                   //if answer is correct display feedback and increment count of correct answers
                   if(smallest == answer)
                   {
                       printPositiveFeedback(feedback);
                       numberCorrect++;
                   }
                   //else display negative feedback
                   else
                       printNegativeFeedback(feedback);
               }
           }
           //display the number of corrects
           System.out.println("\nYou got " + numberCorrect + " correct out of 10.");
           //check if user wishes to continue
           System.out.print("\nDo you wish to play again(y/n): " );
           input.nextLine();
           userChoice = input.nextLine();
           if(userChoice.equalsIgnoreCase("y"))
               repeat = true;
           else
               repeat = false;  
           System.out.println();
       }

   }

   //function that read the level the user wants to attempt
   public static int getLevel(Scanner input)
   {
       int level;
       //display options to the user
       System.out.println("Which level you want attempt:");
       System.out.println("1. Easy");
       System.out.println("2. Medium");
       System.out.println("3. Hard");
       //read users choice
       System.out.print("Choose a level: ");
       level = input.nextInt();
       //check if input is valid
       while(level < 1 || level > 3)
       {
           //re prompt if user choice is invalid
           System.out.println("Invalid choice.");
           System.out.print("Choose a level: ");
           level = input.nextInt();
       }
       return level;
   }

   public static int getProblemType(Scanner input)
   {
       int problemType;
       //display options to the user
       System.out.println("Which problem type want attempt:");
       System.out.println("1. Find Sum");
       System.out.println("2. Find Average");
       System.out.println("3. Find Largest");
       System.out.println("4. Find Smallest");
       //read users choice
       System.out.print("Choose a problem type: ");
       problemType = input.nextInt();
       //check if input is valid
       while(problemType < 1 || problemType > 4)
       {
           //re prompt if user choice is invalid
           System.out.println("Invalid choice.");
           System.out.print("Choose a problem type: ");
           problemType = input.nextInt();
       }
       return problemType;
   }

   //function that displays positive feedback message
   public static void printPositiveFeedback(int n)
   {
       //display message based on number generated
       if(n == 0)
           System.out.println("Correct answer!!");
       else if(n == 1)
           System.out.println("Good job!!");
       else
           System.out.println("Well done!!");
   }

   //function that displays negative feedback message
   public static void printNegativeFeedback(int n)
   {
       //display message based on number generated
       if(n == 0)
           System.out.println("Sorry that's a wrong answer..");
       else if(n == 1)
           System.out.println("Oops.. you are wrong");
       else
           System.out.println("Better luck next time..");
   }
}

Output:

Program Screenshot:

Add a comment
Know the answer?
Add Answer to:
Using Java IDE: Write an application that asks elementary students a set of 10 math problems...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

  • Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your...

    Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your pseudocode and C-program, use only what you have learned in this class so far. (Menu) Design a menu for question 2 and 3. So far, you use one program to solve all lab questions. But some of you may feel awkward when you want to demo/test only one lab question. To overcome that, your program should show a menu so that the users of...

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

  • Instructions Basically, you will modify the mathq program to make it satisfy a different set of...

    Instructions Basically, you will modify the mathq program to make it satisfy a different set of requirements, and fix what is not working in it. Specifically, imagine that the client for whom we created the mathq program for would now like some changes. To be exact: Part 1: They want it to provide addition and subtraction problems as well as multiplication and division. They still want the choice to be random, as before, but now the problem is randomly multiplication,...

  • x= Suppose you are building a program for teaching kids' math. Write a java program the...

    x= Suppose you are building a program for teaching kids' math. Write a java program the does the following: 1. Ask the user if he/she wants to sign-up a. If yes continue to step 2 b. If no Display the message "Thank you, Have a nice Day 2. Ask the user to enter a username. 3. Ask the user to enter a password with at least 8 characters long 4. Write a method with the following header: public static Boolean...

  • USING C LANGUAGE _Design_ a program that asks the user to answer (easy) multiplication problems. It...

    USING C LANGUAGE _Design_ a program that asks the user to answer (easy) multiplication problems. It is up to you how many math problems you want it to present. The numbers should be chosen at random. The program will then display the user stats: - number of problems answered correctly out of the total - percent correct - grade letter (>= 90 is A, >= 80 is B, >= 70 is C, >=60 is D, < 60 is F)   Example...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would...

    mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would get displayed with "+" between them. The user should enter the sum of the two numbers. The program should print "Incorrect" if the user enters a wrong answer and re-prompts the user to re-enter the answer again. Limit the number of incorrect tries to 3. After 3 incorrect tries print the correct answer. The program should print a message like "Correct!" if the user...

  • Write a MIPS math quiz program in MARS. The program should start with a friendly user...

    Write a MIPS math quiz program in MARS. The program should start with a friendly user greeting. From there, it should generate a random arithmetic problem. Your program will need to generate three random things: the first and second operand and the operator to use. Your program should generate random positive integers no greater than 20 for the operands. The possible operators are +, -, * and / (division). The user should be prompted for an answer to the problem....

  • mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would...

    mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would get displayed with "+" between them. The user should enter the sum of the two numbers. The program should print "Incorrect" if the user enters a wrong answer and re-prompts the user to re-enter the answer again. Limit the number of incorrect tries to 3. After 3 incorrect tries print the correct answer. The program should print a message like "Correct!" if the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT