Good Afternoon ..
As you may have noticed i’ve been working on methods for a week now and i have a question which i don’t seem to understand how it goes … i tried it but i need you guys to check if am on the right track …
Question:
Create a class LearnToMultiply
The class should contain one main method. In the main method, use Math.random method to produce two positive one digit integers(between 1 and 10). The program should ask the user about the result of multiplying these two integers. “HOW MUCH IS 3 TIMES 7?”
The user will input the answer. The program checks the answer, if it is correct, it will display “Excellent, You got it”. If it is wrong it will display “No, Try again”. The user will continue to enter until he guesses the correct answer. The program will display at the end, the number of trials.
[code]
import javax.swing.JOptionPane;
import java.lang.Math;
class LearnToMultiply
{
public static void main (String args[])
{
String strmsg1, strmsg2, strmsg3;
String strNumber;
int Number;
int counter;
strNumber= JOptionPane.showInputDialog(“How much is 3 times 7 ? “);
Number= Integer.parseInt (strNumber);
strmsg1= “Excellent. You got it”;
strmsg2= “No. Try again”;
Number = 1 + ( int ) ( Math.random() * 10);
counter = 0;
if (Number == 21)
{
JOptionPane.showMessageDialog(null, strmsg1);
}
else if (Number != 21)
{
JOptionPane.showMessageDialog(null, strmsg2);
}
for ( counter= 0; counter < 11; counter++);
}// end for
}// end class
I feel dizzy :p from 2 hours am working on this
:p