-bash-4.1$ cat One.java
import java.util.*;
import java.text.*;

abstract class Shape implements Comparable<Shape> {
  abstract public double area();
  public int compareTo(Shape other) {
    if (this.area() < other.area()) return -1;
    else if (this.area() > other.area()) return 1;
    else return 0;
  }
}

class Circle extends Shape {
  int radius;
  Circle(int radius) {
    this.radius = radius;
  }
  public double area() {
    return Math.PI * this.radius * this.radius;
  }
  public String toString() {
    DecimalFormat leslie = new DecimalFormat("#.##");
    return "Circle(" + leslie.format(this.area()) + ")";
  }
}

class One {
  public static void main(String[] args) {
    ArrayList<Shape> shapes;
    shapes = new ArrayList<Shape>();
    shapes.add(new Circle(4));
    shapes.add(new Circle(8));
    shapes.add(new Circle(2));
    shapes.add(new Circle(1));
    shapes.add(new Circle(7));
    shapes.add(new Circle(5));
    shapes.add(new Circle(3));
    System.out.println( shapes );
    Collections.sort( shapes );
    System.out.println( shapes );

    java.util.Collections.sort( shapes, new Examiner() ); // you need to define this [1]
    System.out.println( shapes );

  }
}

class Examiner implements Comparator<Shape> {
  public int compare(Shape a, Shape b) {
    if (a.area() > b.area()) return -1;
    else if (a.area() < b.area()) return 1;
    else return 0;
  }
}

// ------------(part one above)-------------
// to finish part II add your own definition of Comparator<T> below
// also define a second sort in Collections and remove java.util. in line [1] then compile and run

interface Comparable<T> {
  public int compareTo(T other);
}

class Collections {
  public static <T extends Comparable<T>> void sort(ArrayList<T> students) {
    boolean sorted = false;
    while(! sorted) {
      sorted = true;
      for (int i = 0; i < students.size() - 1; i = i + 1) {
        T a = students.get(i);
        T b = students.get(i+1);
        if (a.compareTo(b) > 0) {
           students.set(i, b);
           students.set(i+1, a);
           sorted = false;
           System.out.println("Swapping " + a + " with " + b);
        }
      }
    }
  }
}
-bash-4.1$ javac One.java
j-bash-4.1$ java One
[Circle(50.27), Circle(201.06), Circle(12.57), Circle(3.14), Circle(153.94), Circle(78.54), Circle(28.27)]
Swapping Circle(201.06) with Circle(12.57)
Swapping Circle(201.06) with Circle(3.14)
Swapping Circle(201.06) with Circle(153.94)
Swapping Circle(201.06) with Circle(78.54)
Swapping Circle(201.06) with Circle(28.27)
Swapping Circle(50.27) with Circle(12.57)
Swapping Circle(50.27) with Circle(3.14)
Swapping Circle(153.94) with Circle(78.54)
Swapping Circle(153.94) with Circle(28.27)
Swapping Circle(12.57) with Circle(3.14)
Swapping Circle(78.54) with Circle(28.27)
Swapping Circle(50.27) with Circle(28.27)
[Circle(3.14), Circle(12.57), Circle(28.27), Circle(50.27), Circle(78.54), Circle(153.94), Circle(201.06)]
[Circle(201.06), Circle(153.94), Circle(78.54), Circle(50.27), Circle(28.27), Circle(12.57), Circle(3.14)]
-bash-4.1$