-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentScoreInfo.java
More file actions
108 lines (83 loc) · 2.99 KB
/
Copy pathStudentScoreInfo.java
File metadata and controls
108 lines (83 loc) · 2.99 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.*;
import java.util.stream.*;
class Student {
private String studentId;
private String studentName;
private int percentageScore;
public Student() {}
public Student(String studentId, String studentName, int percentageScore) {
this.studentId = studentId;
this.studentName = studentName;
this.percentageScore = percentageScore;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getPercentageScore() {
return percentageScore;
}
public void setPercentageScore(int percentageScore) {
this.percentageScore = percentageScore;
}
@Override
public String toString() {
return "Student Id: " + studentId + ", Student Name: " + studentName + ", Percentage Score: " + percentageScore;
}
}
class StudentUtility {
List<Student> studentList = new ArrayList<>();
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this.studentList = studentList;
}
public Stream<Student> convertToStream() {
return studentList.stream();
}
public List<Student> filterStudentInfo(Stream<Student> studentStream, int score) {
return studentStream
.filter(student -> student.getPercentageScore() > score)
.sorted(Comparator.comparingInt(Student::getPercentageScore).reversed())
.collect(Collectors.toList());
}
}
public class StudentScoreInfo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StudentUtility utility = new StudentUtility();
System.out.println("Enter the number of students");
int n = sc.nextInt();
sc.nextLine(); // consume the newline
if (n <= 0) {
System.out.println("Invalid number of students");
return;
}
List<Student> students = new ArrayList<>();
System.out.println("Enter the student details");
for (int i = 0; i < n; i++) {
String[] details = sc.nextLine().split("/");
students.add(new Student(details[0], details[1], Integer.parseInt(details[2])));
}
utility.setStudentList(students);
System.out.println("Enter the score to search:");
int score = sc.nextInt();
List<Student> filteredStudents = utility.filterStudentInfo(utility.convertToStream(), score);
if (filteredStudents.isEmpty()) {
System.out.println("No Students found");
} else {
System.out.println("Filtered students info whose score is above " + score + ":");
filteredStudents.forEach(System.out::println);
}
sc.close();
}
}