
/*
*Antonio Aguilera
*CSCI 2350
*01.24.05
*Random.java
Purpose: Computers are playing an increasing roll in education. Write a program that will help an
elementary school student learn multiplication. Use Math.random() to generate two positive one-digit
integers. The program should display a question in an input dialog box:: “How much is 6 times 7?” The
student types the answer in and presses OK. The program checks the student’s answer and displays “That is
Correct” or “Sorry, the answer is ?” (fill-in the correct answer) in a message dialog box.
You must include a method multiply() which accepts two numbers and returns the product of the two
numbers.
*/
import javax.swing.JOptionPane;
public class Random
{
public static void main ( String args[])
{
int num1;
int num2, end;
String result;
num1 = 1+ (int) (Math.random()*9);
num2 = 1 +(int) (Math.random()*9);
result = JOptionPane.showInputDialog(null, "What is " + num1 + " times "
+ num2 + " ?");
end = Integer.parseInt(result);
if(end == multiply(num1,num2)){
JOptionPane.showMessageDialog(null,"That is correct");
}
else
JOptionPane.showMessageDialog(null,"Sorry, the answer is " +
multiply(num1,num2)+ ".");
}
public static int multiply(int x, int z)
{
return x*z;
}
}