import java.util.Iterator;
import java.util.TreeSet;
public class Main {
public static void main(String[] args){
TreeSet<ClassMate> classMates = new TreeSet<>();
classMates.add(new ClassMate("Lilith", 10, 6));
classMates.add(new ClassMate("jack", 10, 6));
classMates.add(new ClassMate("jack", 10, 6));
classMates.add(new ClassMate("Adeam", 5, 7));
Iterator it = classMates.iterator();
it.forEachRemaining(e -> System.out.println(e.toString()));
}
}
class ClassMate implements Comparable < ClassMate > {
private String name;
private int age;
private int grade;
@Override
public String toString() {
return "name:" + this.name + "\t" + "age:" + this.age + "\t" + "grade:" + this.grade;
}
public ClassMate(String name, int age, int grade){
this.name = name;
this.age = age;
this.grade = grade;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
@Override
public int compareTo(ClassMate o) {
if (this.age > o.age){
return 1;
}else if (this.age < o.age){
return -1;
}else
return this.name.compareTo(o.name);
}
}