public class Candidate implements Comparable { String name; int count; int sum; public String toString() { return this.name + "(" + this.sum + "/" + this.count + ")"; } Candidate(String name, int count, int sum) { this.name = name; this.count = count; this.sum = sum; } public double average() { return (double) this.sum / this.count; } public int compareTo(Candidate other) { if (this.sum > other.sum) return -1; else if (this.sum < other.sum) return 1; return this.name.compareTo(other.name); } }