- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Sort.java
More file actions
Latest commit
53 lines (48 loc) · 1.1 KB
/
Copy pathJava Sort.java
File metadata and controls
53 lines (48 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
importjava.util.*;
classStudentimplementsComparable<Student>{
privateintid;
privateStringfname;
privatedoublecgpa;
publicStudent(intid, Stringfname, doublecgpa) {
super();
this.id = id;
this.fname = fname;
this.cgpa = cgpa;
}
publicintgetId() {
returnid;
}
publicStringgetFname() {
returnfname;
}
publicdoublegetCgpa() {
returncgpa;
}
publicintcompareTo(Studento){
intc=Double.valueOf(cgpa).compareTo(o.cgpa);
if(c!=0)return -c;
c=fname.compareTo(o.fname);
if(c!=0)returnc;
c=Integer.valueOf(id).compareTo(o.id);
returnc;
}
}
classSolution{
publicstaticvoidmain(String[] args){
Scannerin = newScanner(System.in);
inttestCases = Integer.parseInt(in.nextLine());
List<Student> studentList = newArrayList<Student>();
while(testCases>0){
intid = in.nextInt();
Stringfname = in.next();
doublecgpa = in.nextDouble();
Studentst = newStudent(id, fname, cgpa);
studentList.add(st);
testCases--;
}
Collections.sort(studentList);
for(Studentst: studentList){
System.out.println(st.getFname());
}
}
}