-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradingStudents.java
41 lines (39 loc) · 1.28 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
41
import java.util.*;
public class gradingStudents {
public static List<Integer> gradingStudents(List<Integer> grades) {
// Write your code here
List<Integer> lastGrades = new ArrayList<>();
for(int i = 0; i<grades.size();i++){
int rounded = (grades.get(i) + 4) / 5 * 5;
if(grades.get(i)<38) {
int grade = grades.get(i);
lastGrades.add(grade);
}
else if(rounded-grades.get(i)<3){
grades.set(i,rounded);
lastGrades.add(grades.get(i));
}
else if(rounded-grades.get(i)==3){
int grade = grades.get(i);
lastGrades.add(grade);
}
else if(rounded-grades.get(i)>3){
int grade = grades.get(i);
lastGrades.add(grade);
}
}
return lastGrades;
}
public static void main(String[]args){
List<Integer> grades = new ArrayList<>();
//sample test case
grades.add(23);
grades.add(80);
grades.add(96);
grades.add(18);
List<Integer> lastGrades = gradingStudents(grades);
for(int i = 0; i<lastGrades.size();i++){
System.out.println(lastGrades.get(i));
}
}
}