Question

on a math game you will ask the student 10 questions (addition and subtraction only). If...

on a math game you will ask the student 10 questions (addition and subtraction only). If the student gets at least 1 question wrong the game keep going until his percent of correct answer reaches 80% or he he got 25 questions. the questions should be personalized. If the student got an addition question wrong the next question should be addition and vice versa.

It needs to be done in Java. And a while loop needs to be used on the additional questions. Thanks

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

CODE :-

import java.util.*; public class B1304 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); Random r=new Random(); int a=0,b=0;// these are the two input variable. int i=1;//i variable is used for keeping the track of number of questions. int count=0;//count variable for counting number of correct answer. int flag=0;//flag variable for keeping the track of whether to do addition or //subtraction. System.out.println("******* MATH GAME *******"); while(i<=10) { //I am generating the numbers randomly within the range of 0 to 100. a=r.nextInt(100); b=r.nextInt(100); //if flag=0, than it should be addition. //if flag=1, than it should be subtraction. if(flag==0) { System.out.print("Question "+i+": "+a+"+"+b+"="); int res=sc.nextInt(); if(a+b==res) { count++; flag=1; } } else { System.out.print("Question "+i+": "+a+"-"+b+"="); int res=sc.nextInt(); if(a-b==res) { count++; flag=0; } } i++; } //if all the questions are answered correctly than exit, if not than continue //the game. if(count==10) { System.out.println("!!!!GAME OVER!!!!"); System.out.println("CONGRATULATIONS YOU HAVE ANSWERED ALL THE QUESTIONS CORRECTLY"); } else { //the bellow loop will run until the player scores 80% or the no. of //questions reach 25. while(i<=25) { if((int)(((double)count/25)*100)==80) { break; } a=r.nextInt(100); b=r.nextInt(100); if(flag==0) { System.out.print("Question "+i+": "+a+"+"+b+"="); int res=sc.nextInt(); if(a+b==res) { count++; flag=1; } } else { System.out.print("Question "+i+": "+a+"-"+b+"="); int res=sc.nextInt(); if(a-b==res) { count++; flag=0; } } i++; System.out.println("Per="+(int)(((double)count/25)*100)+"%"); } System.out.println("!!!!GAME OVER!!!!"); } } }

OUTPUT :-

Add a comment
Know the answer?
Add Answer to:
on a math game you will ask the student 10 questions (addition and subtraction only). If...
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
  • Android / Java / Please Upload your homework. Copy the screenshot and then paste it to...

    Android / Java / Please Upload your homework. Copy the screenshot and then paste it to this word document. Then zip your word file and java files. Note: if your android project is too big, you can just zip all of the needed xml files and java files. Computer-Assisted Instruction App) Create an app that will help an elementary school student learn multiplication. Select two positive one-digit integers. The app should then prompt the user with a question, such as...

  • Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to...

    Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and...

  • Read description carefully. Needs to catch exceptions and still be able to keep the program going...

    Read description carefully. Needs to catch exceptions and still be able to keep the program going on past the error. Program should allow user to keep going until he or she quits Math tutor) Write a program that displays a menu as shown in the sample run. You can enter 1, 2. 3, or 4 for choosing an addition. subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter...

  • I am writing a Java program. My program would ask two questions: (1) 1+1=? (2) 2+1...

    I am writing a Java program. My program would ask two questions: (1) 1+1=? (2) 2+1 =? Show one question at a time on the console. The program allows users to input answers via a command-line (no GUI). Give users five seconds to answer each question. The next question would show ONLY when the user answers the question correctly OR when the time is up. Once users answer the question correctly within the given time, the next question needs to...

  • java In this project you will implement a trivia game. It will ask random trivia questions,...

    java In this project you will implement a trivia game. It will ask random trivia questions, evaluate their answers and keep score. The project will also have an administrative module that will allow for managing the question bank. Question bank management will include adding new questions, deleting questions and displaying all of the questions, answers and point values. 2. The project can be a GUI or a menu based command line program. 3. Project details 1. Create a class to...

  • 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 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...

  • Write a program that will help a student learn multiplication. Use SecureRandom object to produce two...

    Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and let the...

  • Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted...

    Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a SecureRandom object to produce two positive one-digit integers (you will need to look up how to do this). The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s...

  • Programming in C: Write a program that will help an elementary school student learn multiplication. Use...

    Programming in C: Write a program that will help an elementary school student learn multiplication. Use the random number generator to produce two positive integers between 1 and 12 inclusive. It should then type a question such as:             How much is 6 times 7? The student then types the answer. Your program checks the students’ answer. If it is correct, print a message such as Very good!   If the answer is wrong, print a message such as No. Please...

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