## KPS

im creating a java program using Jgrasp and im completely stuck on how to apply my random operator to calculate two random numbers? heres my code:

``````//Import Random Generator
import java.util.Random;
import java.util.*;
//Program name
class TimesTableTestTimer
{//open main
public static void main(String[] args)
{//Create while loop to restart
char Restart = 'Y';
while (Restart == 'Y' | Restart == 'y')
{
Random Generator = new Random();
//Create Random Operators
char[] chars = new char[]{'+','-','/','*'};
int r = Generator.nextInt(chars.length);
char op = chars[r];
//Create 2 Random Number Generators
float X = 1 + (int)(Math.random()*13);
float X2 = 1 + (int)(Math.random()*13);

{//Timer variables
double t1, t2, ttaken;
String Key = "";
{
System.out.println("Welcome to the Times Table Test Timer!");

System.out.println("Press the 'Enter' Key to start the Next Question");
//Start Timer
{
for (int i = 1;i <= 4;i++)
{
t1 = (System.currentTimeMillis());

float   Sum = (X + X2); //How to use the random operator instead of '+'

System.out.println(X +" ? "+X2+" = "+Sum+" "+op);
System.out.println("What is the Value of '?'...");

System.out.println("Correct!");
else
System.out.println("Incorrect!");

//End Timer
t2 = (System.currentTimeMillis());
ttaken = t2-t1;
System.out.println("Your time taken is "+ttaken/1000+" Seconds.");
}//Finish sequence to loop

System.out.println("Thank you for completing the Quiz");
System.out.println("Press 'y' to restart or any other key to exit");
}//Close restart option

}//Close Loop
}//Close Introduction
}//Close Variables
}//Close Randoms
}//Close While Loop
}//Close Main
``````

ive tried looking everywhere but the forums seem to be the best place for help thanks in advanced

## Antenka 274

Hello, KPS
You can try to look in class Operation...

## KPS

cheers ill try looking that up

## KPS

yehhh...im a bit lost now

## Antenka 274

Here's little example for better understanding:

``````Operation op = new Minus();  // you can dynamicly set the operation
XObject x = new XNumber(5.0); //creating numbers
XObject x1 = new XNumber(4.0); //creating numbers
XObject r = op.operate(x, x1); //doing operation``````