-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection_Sort.java
More file actions
67 lines (61 loc) · 2.14 KB
/
Copy pathSelection_Sort.java
File metadata and controls
67 lines (61 loc) · 2.14 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Write a program that takes the details of Students (name, roll number, address, CGPA) and sort it in a non-decreasing order using Selection sort based on CGPA.
import java.util.*;
class student_record {
String name;
int roll_number;
String address;
double CGPA;
student_record(String name, int roll_number, String address, double CGPA){
super();
this.name = name;
this.roll_number = roll_number;
this.address = address;
this.CGPA = CGPA;
}
String name(){
return name;
}
int roll_number(){
return roll_number;
}
String address(){
return address;
}
double CGPA(){
return CGPA;
}
}
class Selection_Sort_CGPA{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number of students in the class : \n");
int no_of_students = Integer.parseInt(sc.nextLine());
List<student_record > Studentlist = new ArrayList<student_record>();
while (no_of_students > 0) {
System.out.println("Enter the Name of the student : \n");
String name = sc.next();
System.out.println("Enter the student Roll Number : \n");
int roll_number = sc.nextInt();
System.out.println("Enter the Address of the student : \n");
String address = sc.next();
System.out.println("Enter the CGPA of the student : \n");
double CGPA = sc.nextDouble();
student_record st = new student_record(name, roll_number, address, CGPA);
Studentlist.add(st);
no_of_students--;
}
Collections.sort(Studentlist, new Comparator<student_record>() {
public int compare(student_record s1, student_record s2){
if(s1.CGPA() > s2.CGPA()){
return 1;
}
return -1;
}
}
);
System.out.println("The Sorted Array of the student's CGPA is : \n");
for(student_record s: Studentlist){
System.out.println(s.name());
}
}
}