Question

In: Computer Science

Write a JAVA application that asks elementary students a set of 10 math problems First ask...

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

  1. First ask the user for a level and a problem type.
  2. You need to validate the level and problem type and loop until the user enters a correct one.
  3. 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.
  4. Each problem will consist of three randomly generated operands.
  5. There should be 4 problem types. Problem type 1 requires the student to find the sum of the three numbers, 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 three numbers, and problem type 4 requires the user to find the smallest of the three numbers.
  6. The program should ask the user 10 questions.
  7. 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.
  8. The program should provide individual feedback for each problem. There should be 3 different positive and 3 different negative feedbacks chosen from for each problem.
  9. 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.

Solutions

Expert Solution

//---------- MathOps.java -------------
import java.util.Random;
import java.util.Scanner;
class MathOps
{
   Scanner in ;
   Random rand;
   String[] positive = {"Good, You got it","WoW, You are a genious","You are rocking. Keep it up"};
   String[] negative = {"Oops, Wrong answer","Sorry, Wrong answer. keep practice","You missed again, keep focus"};
   MathOps()
   {
       in = new Scanner(System.in);
       rand = new Random();
   }
   public int getRand(int range)
   {
       return rand.nextInt(range);
   }
   public void printLevels()
   {
       System.out.println("\n------------ Select Math Level -----------\n");
       System.out.println("1. Level-1 values of Operands in the range of 0-9");
       System.out.println("2. Level-2 values of Operands in the range of 0-99");
       System.out.println("3. Level-3 values of Operands in the range of 0-999");
       System.out.print("Enter your choice: ");
   }
   public int getLevels()
   {
       boolean isValid = false;
       int level = 0;
       while(!isValid)
       {
           try
           {
               printLevels();
               level = in.nextInt();
               if(level <1 || level > 3)
               {
                   System.out.println("\nInvalid Level entered. Try Again");
               }
               else
               {
                   isValid = true;
               }
           }
           catch(Exception e)
           {
               System.out.println("\nInvalid Level entered. Try Again");
               in.nextLine();
           }
       }
       return level;
   }
   public int getAnswer(String question)
   {
       boolean isValid =false;
       int ans=-1;
       while(!isValid)
       {
           try
           {
               System.out.print("\n"+question);
               ans = in.nextInt();
               isValid = true;
           }
           catch(Exception e)
           {
               in.nextLine();
               System.out.println("\nInvalid Answer, Answer must be a integer");
           }
       }
       return ans;
   }
   public int getSum(int opOne,int opTwo , int opThree)
   {
       return opOne + opTwo + opThree;
   }
   public int getIntAverage(int opOne,int opTwo , int opThree)
   {
       return getSum(opOne,opTwo,opThree)/3;
   }
   public int getMax(int opOne,int opTwo , int opThree)
   {
       return Math.max(opOne,Math.max(opTwo,opThree));
   }
  
   public int getMin(int opOne,int opTwo , int opThree)
   {
       return Math.min(opOne,Math.min(opTwo,opThree));
   }
   public void simulate(int level)
   {
       int opRange;
       if(level == 1)
       {
           opRange = 10;
       }
       else if(level == 2)
       {
           opRange = 100;
       }
       else
       {
           opRange = 1000;
       }
      
       int prblmType;
       int opOne;
       int opTwo;
       int opThree;
       int ans;
       int correctAns;
       int score = 0;
      
       for(int i =1 ; i <= 10; i++)
       {
           prblmType = getRand(4)+1;
           //System.out.println("\nProblme Type: "+prblmType);
           opOne = getRand(opRange);
           opTwo = getRand(opRange);
           opThree = getRand(opRange);
           System.out.println("\n-------------------------------------------------------");
           if(prblmType == 1)
           {
               ans = getAnswer(String.format("Sum of %d , %d , %d = ",opOne,opTwo,opThree));
               correctAns = getSum(opOne,opTwo,opThree);
              
           }
           else if(prblmType == 2)
           {
               ans = getAnswer(String.format("Integer average of %d , %d , %d = ",opOne,opTwo,opThree));
               correctAns = getIntAverage(opOne,opTwo,opThree);
           }
           else if(prblmType == 3)
           {
               ans = getAnswer(String.format("Maximum of %d , %d , %d = ",opOne,opTwo,opThree));
               correctAns = getMax(opOne,opTwo,opThree);
              
           }
           else
           {
               ans = getAnswer(String.format("Minimum of %d , %d , %d = ",opOne,opTwo,opThree));
               correctAns = getMin(opOne,opTwo,opThree);
           }
           if(ans == correctAns)
           {
               score++;
               System.out.println("\n"+positive[getRand(3)]);
              
           }
           else
           {
               System.out.println("\n"+negative[getRand(3)]);
               System.out.println("\nThe Correct Answer is: "+correctAns);
           }
          
       }
       System.out.println("\n\nYour Total Score: "+score);
   }
   public static void main(String[] args)
   {
       MathOps tester = new MathOps();
       Scanner in= new Scanner(System.in);
       int level;
       String choice;
       do
       {
           level = tester.getLevels();
           tester.simulate(level);
           System.out.println("Do you want to play again?n.no or any key to continue: ");
           choice = in.nextLine();
       }while(!choice.equalsIgnoreCase("n"));
      
   }
}
/*
* -------------- OUTPUT ----------
*
------------ Select Math Level -----------

1. Level-1 values of Operands in the range of 0-9
2. Level-2 values of Operands in the range of 0-99
3. Level-3 values of Operands in the range of 0-999
Enter your choice: 1

-------------------------------------------------------

Maximum of 8 , 0 , 4 = 0

Oops, Wrong answer

The Correct Answer is: 8

-------------------------------------------------------

Integer average of 9 , 6 , 8 = 7

WoW, You are a genious

-------------------------------------------------------

Sum of 0 , 1 , 2 = 3

You are rocking. Keep it up

-------------------------------------------------------

Minimum of 8 , 6 , 9 = 3

Oops, Wrong answer

The Correct Answer is: 6

-------------------------------------------------------

Minimum of 9 , 9 , 1 = 9

You missed again, keep focus

The Correct Answer is: 1

-------------------------------------------------------

Sum of 8 , 7 , 0 = 9

Sorry, Wrong answer. keep practice

The Correct Answer is: 15

-------------------------------------------------------

Integer average of 5 , 7 , 0 = 4

Good, You got it

-------------------------------------------------------

Integer average of 6 , 0 , 0 = 2

WoW, You are a genious

-------------------------------------------------------

Integer average of 8 , 2 , 0 = 9

Sorry, Wrong answer. keep practice

The Correct Answer is: 3

-------------------------------------------------------

Maximum of 8 , 3 , 7 = 4

Oops, Wrong answer

The Correct Answer is: 8


Your Total Score: 4
Do you want to play again?n.no or any key to continue:
y

------------ Select Math Level -----------

1. Level-1 values of Operands in the range of 0-9
2. Level-2 values of Operands in the range of 0-99
3. Level-3 values of Operands in the range of 0-999
Enter your choice: 3

-------------------------------------------------------

Maximum of 22 , 691 , 310 = 1

You missed again, keep focus

The Correct Answer is: 691

-------------------------------------------------------

Integer average of 432 , 760 , 604 = 2

You missed again, keep focus

The Correct Answer is: 598

-------------------------------------------------------

Maximum of 563 , 94 , 215 = 3

Sorry, Wrong answer. keep practice

The Correct Answer is: 563

-------------------------------------------------------

Integer average of 120 , 245 , 573 = 4

Sorry, Wrong answer. keep practice

The Correct Answer is: 312

-------------------------------------------------------

Integer average of 506 , 47 , 761 = 5

Sorry, Wrong answer. keep practice

The Correct Answer is: 438

-------------------------------------------------------

Integer average of 312 , 8 , 934 = 6

You missed again, keep focus

The Correct Answer is: 418

-------------------------------------------------------

Maximum of 905 , 380 , 995 = 7

Sorry, Wrong answer. keep practice

The Correct Answer is: 995

-------------------------------------------------------

Integer average of 966 , 886 , 775 = 8

You missed again, keep focus

The Correct Answer is: 875

-------------------------------------------------------

Integer average of 513 , 340 , 56 = 9

You missed again, keep focus

The Correct Answer is: 303

-------------------------------------------------------

Integer average of 302 , 422 , 984 = 10

Sorry, Wrong answer. keep practice

The Correct Answer is: 569


Your Total Score: 0
Do you want to play again?n.no or any key to continue:
n


------------------
(program exited with code: 0)

Press any key to continue . . .
*/



Related Solutions

Write a JAVA application that asks elementary students a set of 10 math problems First ask...
Write a JAVA 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...
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will...
Exercise Overview Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+, -, *, /), the range of the factors to be used in the problems, and the number of problems to work. The system will provide problems, evaluate user responses to the problems, score the problems, and provide statistics about the session at the end. Functional Requirements User enters name at the beginning of a session. System covers four...
Write a Java program to do the following: Ask the user to enter 10 first names...
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard. 1) Display the list of names one per line on the Console. 2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
1) Write Java application that asks the user to enter the cost of each apple and...
1) Write Java application that asks the user to enter the cost of each apple and number of apples bought. Application obtains the values from the user and prints the total cost of apples. 2) Write a java application that computes the cost of 135 apples, where the cost of each apple is $0.30. 3)Write a java application that prepares the Stationery List. Various entries in the table must be obtained from the user. Display the Stationary list in the...
Write a program in Java that first asks the user to type in today's price of...
Write a program in Java that first asks the user to type in today's price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel to denote the end of dollar input. THEN the program reads a sequence of yen amounts and converts them to dollars. The second sequence is terminated by another zero value.
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks...
Create a Java application called ValidatePassword to validate a user’s password. Write a program that asks for a password, then asks again to confirm it. If the passwords don’t match or the rules are not fulfilled, prompt again. Your program should include a method that checks whether a password is valid. From that method, call a different method to validate the uppercase, lowercase, and digit requirements for a valid password. Your program should contain at least four methods in addition...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
Write a java console application,. It simulates the vending machine and ask two questions. When you...
Write a java console application,. It simulates the vending machine and ask two questions. When you run your code, it will do following: Computer output: What item you want? User input: Soda If user input is Soda Computer output: How many cans do you want? User input:            3 Computer output: Please pay $3.00. END The vending machine has 3 items for sale: Soda the price is $1.50/can. Computer should ask “How many cans do you want?” Chips, the price is $1.20/bag....
Write a java program that asks user to enter a set of positive integer values. When...
Write a java program that asks user to enter a set of positive integer values. When the user stops (think of sentinel value to stop), the program display the maximum value entered by the user. Your program should recognize if no value is entered without using counter.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT