Howdy.

Write the simplest shortest program that sorts objects via the 
Comparator interface.

import java.util.*; 

class Squirrel implements Comparable<Squirrel> {
  String name;
  double bushiness; 
  int wingSpan;
  Squirrel(String name, double b, int w) {
    this.name = name;
    this.bushiness = b;
    this.wingSpan = w;
  }
  public int compareTo(Squirrel s) {
     if (this.bushiness < s.bushiness) return -1; // this in front of s
     else if (this.bushiness > s.bushiness) return 1; // s in front of this 
     else return 0; // they have the same bushiness
  }
  public String toString() { 
    return this.name + "(" + this.bushiness + "," + this.wingSpan + ")"; 
  }
  public static void main(String[] args) {
    ArrayList<Squirrel> a = new ArrayList<Squirrel>(); 
    a.add(new Squirrel("Geoff" ,  7, 12)); 
    a.add(new Squirrel("Cindy" , 77, 77)); 
    a.add(new Squirrel("Marvin", 12, 11)); 
    a.add(new Squirrel("Pablo" ,  3,  9)); 
    a.add(new Squirrel("Frank" ,  5,  5)); 
    System.out.println( a ); 
  }
}

--

import java.util.*; 

class Squirrel implements Comparable<Squirrel> {
  String name;
  double bushiness; 
  int wingSpan;
  Squirrel(String name, double b, int w) {
    this.name = name;
    this.bushiness = b;
    this.wingSpan = w;
  }
  public int compareTo(Squirrel s) {
     if (this.bushiness < s.bushiness) return -1; // this in front of s
     else if (this.bushiness > s.bushiness) return 1; // s in front of this 
     else return 0; // they have the same bushiness
  }
  public String toString() { 
    return this.name + "(" + this.bushiness + "," + this.wingSpan + ")"; 
  }
  public static void main(String[] args) {
    ArrayList<Squirrel> a = new ArrayList<Squirrel>(); 
    a.add(new Squirrel("Geoff" ,  7, 12)); 
    a.add(new Squirrel("Cindy" , 77, 77)); 
    a.add(new Squirrel("Marvin", 12, 11)); 
    a.add(new Squirrel("Pablo" ,  3,  9)); 
    a.add(new Squirrel("Frank" ,  5,  5)); 
    System.out.println( a ); 
    Collections.sort(a);
    System.out.println(a); 
  }
}

--

import java.util.*; 

class Judge1 implements Comparator<Squirrel> {
  public int compare(Squirrel a, Squirrel b) {
    if (a.name.compareTo(b.name) < 0) return -1; 
    else if (a.name.compareTo(b.name) > 0) return 1; 
    else return 0; 
    // return a.name.compareTo(b.name); 
  }
}

--

import java.util.*; 

class Squirrel implements Comparable<Squirrel> {
  String name;
  double bushiness; 
  int wingSpan;
  Squirrel(String name, double b, int w) {
    this.name = name;
    this.bushiness = b;
    this.wingSpan = w;
  }
  public int compareTo(Squirrel s) {
     if (this.bushiness < s.bushiness) return -1; // this in front of s
     else if (this.bushiness > s.bushiness) return 1; // s in front of this 
     else return 0; // they have the same bushiness
  }
  public String toString() { 
    return this.name + "(" + this.bushiness + "," + this.wingSpan + ")"; 
  }
  public static void main(String[] args) {
    ArrayList<Squirrel> a = new ArrayList<Squirrel>(); 
    a.add(new Squirrel("Geoff" ,  7, 12)); 
    a.add(new Squirrel("Cindy" , 77, 77)); 
    a.add(new Squirrel("Max", 12, 11)); 
    a.add(new Squirrel("Marvin" ,  3,  9)); 
    a.add(new Squirrel("Frank" ,  5,  5)); 
    System.out.println( a ); 
    Collections.sort(a);
    System.out.println(a); 
    // let's sort in alphabetical order 
    Collections.sort(a, new Judge1());
    System.out.println(a); 
  }
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Squirrel
[Geoff(7.0,12), Cindy(77.0,77), Max(12.0,11), Marvin(3.0,9), Frank(5.0,5)]
[Marvin(3.0,9), Frank(5.0,5), Geoff(7.0,12), Max(12.0,11), Cindy(77.0,77)]
[Cindy(77.0,77), Frank(5.0,5), Geoff(7.0,12), Marvin(3.0,9), Max(12.0,11)]