IQ-Calculator(Game) - David Raj
IQ-Calculator(Game) - David Raj
This
Java code implements an IQ calculator game. The game has four operations:
addition, subtraction, multiplication, and division. The code uses the
java.lang and java.util packages to support its functionality.
The
code defines a class "Iqcalculator" which has three methods:
"div", "check", and "option".
The
"div" method generates two random integers between 10 and 110 and a
random number between 1 and 9. The two integers are divided and the result is
stored in the variable "x". If the division results in a whole number
and the divisor is not 1, the division result is passed to the
"check" method. If the division does not result in a whole number,
the "div" method is called again to generate new numbers for division.
The
"check" method takes the division result as an input and prompts the
player to enter a value. If the player's answer is correct, the method returns
10. If the answer is incorrect, it returns 0.
The
"option" method generates 8 random problems selected from the four
operations (addition, subtraction, multiplication, and division). The method
uses a switch statement to choose the operation and calls the "check"
method to calculate the player's score. At the end of the 8 questions, the
player's score is calculated as a percentage of the total possible points (80)
and is displayed to the player.
Finally,
the "main" method takes user input to start the game. If the user
inputs 1, the "option" method is called to start the game. If the
user inputs anything other than 1, an error message is displayed.
Tap on the link to open the code.
Post a Comment