NichoLe
03-24-2005, 07:22 PM
Hello :rolleyes:
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.
import javax.swing.JOptionPane;
import java.lang.Math;
class LearnToMultiply
{
public static void main (String args[])
{
String strmsg1, strmsg2, strmsg3;
String strNumber, strUserNum;
int Number, Number1, Number2, intUserNum;
int counter, intCount;
//ask the user to answer the question
strNumber= JOptionPane.showInputDialog("How much is 3 times 7? ");
Number= Integer.parseInt (strNumber);//converting the entered data [[string]] to integer
strmsg1= "Excellent. You got it";
strmsg2= "No. Try again";
//creating random numbers
Number1 = 1 + ( int ) ( Math.random() * 10);
Number2 = 1 + ( int ) ( Math.random() * 10);
counter = 0; //setting counter to 0
if (Number == 21) //the guessed number is equal to 21
{
JOptionPane.showMessageDialog(null, strmsg1);
}
else //the guessed number is not equal to 21
{
JOptionPane.showMessageDialog(null, strmsg2);
}
while (intUserNum != 21)
{
strUserNum = JOptionPane.showInputDialog("Guess another number");
intUserNum = Integer.parseInt(strUserNum);
intCount = count + 1; //adding to the number of trials
}
}// end loop
}// end class
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.
import javax.swing.JOptionPane;
import java.lang.Math;
class LearnToMultiply
{
public static void main (String args[])
{
String strmsg1, strmsg2, strmsg3;
String strNumber, strUserNum;
int Number, Number1, Number2, intUserNum;
int counter, intCount;
//ask the user to answer the question
strNumber= JOptionPane.showInputDialog("How much is 3 times 7? ");
Number= Integer.parseInt (strNumber);//converting the entered data [[string]] to integer
strmsg1= "Excellent. You got it";
strmsg2= "No. Try again";
//creating random numbers
Number1 = 1 + ( int ) ( Math.random() * 10);
Number2 = 1 + ( int ) ( Math.random() * 10);
counter = 0; //setting counter to 0
if (Number == 21) //the guessed number is equal to 21
{
JOptionPane.showMessageDialog(null, strmsg1);
}
else //the guessed number is not equal to 21
{
JOptionPane.showMessageDialog(null, strmsg2);
}
while (intUserNum != 21)
{
strUserNum = JOptionPane.showInputDialog("Guess another number");
intUserNum = Integer.parseInt(strUserNum);
intCount = count + 1; //adding to the number of trials
}
}// end loop
}// end class