<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.*;


/**
 * An application that can be used to demonstrate the power
 * of the Comparator interface.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class CourseDriver
{
    /**
     * The entry point of the application.
     *
     * @param args  The command-line arguments
     */
    public static void main(String[] args)
    {
        Comparator&lt;Course&gt; comparator;        
        Course[]           prog;
        
        prog = new Course[3];
        prog[0] = new Course("CS", "240", 3);
        prog[1] = new Course("CS", "159", 3);
        prog[2] = new Course("CS", "139", 4);

        comparator = new IDComparator();        
        Arrays.sort(prog, comparator);
        
        System.out.println("\nSorted by ID:");        
        print(prog);
        
        comparator = new CreditComparator();        
        Arrays.sort(prog, comparator);
        
        System.out.println("\nSorted by Credits:");        
        print(prog);
        
    }

    /**
     * Print an array of Course objects.
     *
     * @param courses   The array.
     */
    private static void print(Course[] courses)
    {
        for (int i=0; i&lt;courses.length; i++) 
        {
            System.out.println(courses[i]);
        }
    }
    
}
</pre></body></html>