// Hunter Schafer, CSE 143 // Demonstrates behavior that requires classes to implement the Comparable interface. import java.util.*; public class CollectionsOrdering { public static void main(String[] args) { testStringOrdering(); testCatOrdering(); } // Builds a List of Strings and calls several methods that require Strings // to have a natural ordering. public static void testStringOrdering() { List names = Arrays.asList("Miri", "Ian", "Aaron", "Zach", "Ayaz", "Kyle", "Jin"); System.out.println(names); Collections.sort(names); System.out.println(names); } public static void testCatOrdering() { List cats = new ArrayList(); cats.add(new Cat("Grumpy", 0, 14.5)); cats.add(new Cat("Miri", 9, 13)); cats.add(new Cat("Ian", 6, 50.3)); cats.add(new Cat("Aaron", 3, 10)); cats.add(new Cat("Zach", 5, 16.2)); cats.add(new Cat("Ayaz", 6, 20.0)); cats.add(new Cat("Kyle", 8, 18.0)); cats.add(new Cat("Jin", 7, 12)); cats.add(new Cat("Grumpy", 6, 20.0)); System.out.println(cats); Collections.sort(cats); System.out.println(cats); } }