└── java sort /java sort: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Student implements Comparable{ 4 | private int id; 5 | private String fname; 6 | private double cgpa; 7 | public Student(int id, String fname, double cgpa) { 8 | super(); 9 | this.id = id; 10 | this.fname = fname; 11 | this.cgpa = cgpa; 12 | } 13 | public int getId() { 14 | return id; 15 | } 16 | public String getFname() { 17 | return fname; 18 | } 19 | public double getCgpa() { 20 | return cgpa; 21 | } 22 | //============ code writen here=============== 23 | public int compareTo(Student s){ 24 | if(this.getCgpa() studentList = new ArrayList(); 41 | while(testCases>0){ 42 | int id = in.nextInt(); 43 | String fname = in.next(); 44 | double cgpa = in.nextDouble(); 45 | 46 | Student st = new Student(id, fname, cgpa); 47 | studentList.add(st); 48 | 49 | testCases--; 50 | } 51 | //calling sort method on studentList 52 | Collections.sort(studentList); 53 | 54 | for(Student st: studentList){ 55 | System.out.println(st.getFname()); 56 | } 57 | } 58 | 59 | 60 | } 61 | --------------------------------------------------------------------------------