public class Apple implements Comparable<Apple> { private int id; private Color color; private int weight; //constructor public Apple(int id, Color color, int weight) { this.id = id; this.color = color; this.weight = weight; } // Here we implement the compareTo() method of the Comparable interface. @Override public int compareTo(Apple apple) { return this.getColor().compareTo(apple.getColor()); } // getters / setters and toString() // // enum Color { RED, GREEN } }