Question

In: Computer Science

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

Solutions

Expert Solution

Question:Write a program that asks 5 simple math questions?

Answer:

Math.random() is present in java.lang() library which is the default library in every java program.

Math.random() returns a double value with positive sign.

With the help of typecasting we convert the double value to int.

(int)value [typecasting the value to integer]

Scanner:

Scanner is a class in java.util package used for obtaining the input of the primitive types like int, float, double etc...

nextInt():

nextInt() method scans the next token of the input as an int.

Steps:

I)With the help of Math.random() we select two numbers randomly.

2)Then we ask user to enter the answer.

3)If the answer entered by the user is correct then score is incremented by one.

4)If the answer entered by the user is incorrect then the application says it is incorrect answer and print the correct answer.

5)If user enters incorrect answer score remains same.

6)At the end of the quiz the overall score is printed.

Ouput:


Related Solutions

create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
java script coding to create a math test program with 5 questions.
java script coding to create a math test program with 5 questions.
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Create an application named Rusty2 that asks the user for the dealer cost of a car,...
Create an application named Rusty2 that asks the user for the dealer cost of a car, and the cleaning cost, and then displays the retail cost. Your application should simply send the dealer cost and cleaning cost to the getRetailPrice method in the Dealership class to obtain the retail cost. here below is the dealership class code amd meed to create rusty2 code import java.util.Calendar; public class Dealership { // public static final class variables public static final int YEAR_STARTED...
Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to...
Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to input the number of books checked out and the number of days they are overdue. Pass those values to a method named DisplayFine that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day. The library fine should be displayed in the...
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...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT