You are viewing a single comment's thread. Return to all comments →
class Student implements Comparable<Student>{ private int id; private String fname; private double cgpa; public Student(int id, String fname, double cgpa) { super(); this.id = id; this.fname = fname; this.cgpa = cgpa; } public int getId() { return id; } public String getFname() { return fname; } public double getCgpa() { return cgpa; } public int compareTo(Student student){ if(cgpa == student.cgpa){ if(this.fname.compareTo(student.fname) != 0){ return this.fname.compareTo(student.fname); } else if(id>student.id) return 1; else return -1; } else if(cgpa<student.cgpa) return 1; else return -1; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Sort
You are viewing a single comment's thread. Return to all comments →