LAB 4 – Permutations (20 points)

Create a class to generate permutation of consecutive integers. For example, 1,2,3,4 are consecutive integers. 2,4,3,1 is a permutation of those integers (a rearrangement).

WHAT I EXPECT
- YOU SHOULD ALREADY HAVE A FOLDER called “Labs” (from last class)
- YOU SHOULD ALREADY HAVE A PROJECT called “Lab3Lights”
- Create the classes PermutationGenerator and an application program called “Lab4”

The PermutationGenerator should generate permutations for any range of numbers. Fill an ArrayList, itsNumbers, with the Integers low to high in the constructor (sequentially, in order).

The method nextPermutation returns a list of the itsNumbers in random order with no repetitions. To do this create a new list and remove each number randomly from the original list and append it to the new list. The list element to be removed is selected randomly. Be sure to replace the instance variable holding the ArrayList for the class with the permutation before returning it.

PermutationGenerator pg = new PermutationGenerator(1, 52);
print(pg.nextPermutation(),13); // 13 per line [use EasyFormat or another method to end the lines]

Use the above to test your class and methods. (This shuffles a deck of 52 cards).

Extra Credit – Run an experiment to calculate the number of times a list has to be permutated to be back in order. Write static methods for PermutationTest with these headers:

public static boolean inorder(ArrayList list) // returns true if the list is in increasing order
public static int runExperiment(int lengthOfList, int times) // returns the average number of
//permutations necessary to put a list in order. Do at least (3,100), (4,100), (5,100).