package cn.edu.bjut.chapter6; public class Person implements Comparable { private String name; private char gender; public Person(String name, char gender) { this.name = name; this.gender = gender; } public String getName() { return name; } public void setName(String name) { this.name = name; } public char getGender() { return gender; } public void setGender(char gender) { this.gender = gender; } @Override public String toString() { return (name + "\t" + gender); } @Override public int compareTo(Person o) { if (gender < o.gender) { return -1; } else if (gender > o.gender) { return 1; } else { return name.compareTo(o.name); } } }