001package headfirst.templatemethod.sort;
002
003public class Duck implements Comparable<Duck> {
004        String name;
005        int weight;
006
007        public Duck(String name, int weight) {
008                this.name = name;
009                this.weight = weight;
010        }
011
012        public String toString() {
013                return name + " weighs " + weight;
014        }
015
016
017
018        public int compareTo(Duck otherDuck) {
019                if (this.weight < otherDuck.weight) {
020                        return -1;
021                } else if (this.weight == otherDuck.weight) {
022                        return 0;
023                } else { // this.weight > otherDuck.weight
024                        return 1;
025                }
026        }
027}