-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGradingStudents.java
40 lines (36 loc) · 1.32 KB
/
GradingStudents.java
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
import java.util.*;
public class GradingStudents {
public static List<Integer> gradingStudents(List<Integer> grades) {
int mod = 0, grade = 0, condition = 0;
List<Integer> roundedGrades = new ArrayList<Integer>();
if (!grades.isEmpty()) {
for (int i = 0; i < grades.size(); i++) {
mod = grades.get(i) % 5;
condition = 5 - mod;
if (grades.get(i) >= 38 && condition < 3) {
grade = grades.get(i) + condition;
roundedGrades.add(grade);
} else {
grade = grades.get(i);
roundedGrades.add(grade);
}
}
} else {
System.out.println("There is no data!");
}
return roundedGrades;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
List<Integer> grades = new ArrayList<Integer>();
for (int grades_i = 0; grades_i < n; grades_i++) {
grades.add(in.nextInt());
}
List<Integer> result = gradingStudents(grades);
for (int i = 0; i < result.size(); i++) {
System.out.print(result.get(i) + (i != result.size() - 1 ? "\n" : ""));
}
System.out.println("");
}
}