/**
 * Improve the Sorter code from Lecture 30 so it tests our newly
 * Comparable SorableBunny object.
 *
 * Rest of class is same as previous version.
 * 
 * Lecture 35, Wed Apr 14 2010, CPSC 111
 */
public class SafeBunnySorter
{
    /* we don't have time to cover Java Generics in this course, so
    suppress a possibly confusing warning message */
    @SuppressWarnings("unchecked")        

    public static void sort(Comparable[] objects) 
    {
	int min;
	Comparable temp;
	//select location of next sorted value
	for (int i = 0; i < objects.length-1; i++)
	    {
		min = i;
		//find the smallest value in the remainder of
		//the array to be sorted
		for (int j = i+1; j < objects.length; j++)
		    {
			if ( objects[j].compareTo(objects[min]) < 0) 
			    {
				min = j;
			    }
		    }
		//swap two values in the array
		temp = objects[i];
		objects[i] = objects[min];
		objects[min] = temp;
	    }
	    
	System.out.println("Printing sorted result");
	for (int i = 0; i < objects.length; i++)
	    {
		System.out.println(objects[i]);
	    } 
    }
    public static void main(String[] args)
    {
	Integer[] numbers = {16,3,19,8,12};
	SafeBunnySorter.sort(numbers);
	String[] strings = {"Carson", "Thompson", "Kamara", "Mi"};
	SafeBunnySorter.sort(strings);
	Double[] bunchOfDoubles = {3.14159265,2.7,3.564,7.162};
	SafeBunnySorter.sort(bunchOfDoubles);

        SafeBunny[] bunnies = new SafeBunny[4];
        SafeBunny peter = new SafeBunny(3,6,1,"Peter");
        SafeBunny emily = new SafeBunny(3,4,5,"Emily");
        SafeBunny darlene = new SafeBunny(3,6,1,"Darlene");
        SafeBunny aaron = new SafeBunny(3,4,5,"Aaron");
        
        bunnies[0] = peter;
        bunnies[1] = emily;
        bunnies[2] = darlene;
        bunnies[3] = aaron;
        
        SafeBunnySorter.sort(bunnies); 

	darlene.compareTo("UhOhNotABunny");
    }
}

