import java.util.Random; /** * Program to generate random fractions and multiply them. * * @author Steven Karas */ public class RandomFraction { public static void main(String[] args) { Random rndGenerator = new Random(); /* * If you use two rndGenerators, you may end up with the same number for * x and y. The reason is beyond the scope of the course, but it also * may vary by computer.2 */ // generate two numbers at random int x = rndGenerator.nextInt(); int y = rndGenerator.nextInt(); /* * Another way to do this would be to explictly set b to be the inverse * of a: * * Fraction b = a.reciprocal(); */ // create fractions that are inverses of each other Fraction a = new Fraction(x, y); Fraction b = new Fraction(y, x); /* * Sometimes it is acceptable to not use a helper variable, but we want * you to get in the habit. */ // multiply them and print it out System.out.println("(" + a + ") times (" + b + ") equals " + a.multiply(b)); } }