import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Outputs a sorted list of random rational numbers.
 *
 * @author Drue Coles
 */
public class RationalSortDemo {

    public static void main(String[] args) { 
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        RationalNumber[] rNums = new RationalNumber[10];
        for (int i = 0; i < rNums.length; i++) {
            // numerator and denominator generated randomly in the range [1, 9].
            int x = 1 + rand.nextInt(9);
            int y = 1 + rand.nextInt(9);
            rNums[i] = new RationalNumber(x, y);
        }

        Arrays.sort(rNums);
        for (RationalNumber num : rNums) {
            System.out.printf("%3s%n", num);
        }
    }
}