-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradingStudents.cs
More file actions
42 lines (38 loc) · 1.18 KB
/
GradingStudents.cs
File metadata and controls
42 lines (38 loc) · 1.18 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerRankProblems.Tests.Easy
{
public class GradingStudents
{
/// <summary>
/// Takes a list of integer numbers as Student <paramref name="grades"/>, to calculate the final grades
/// after rounding it if there's a room for this.
/// </summary>
/// <param name="grades"></param>
/// <returns>The list of success grades after rounding it.</returns>
public static List<int> gradingStudents(List<int> grades)
{
var RoundedResult = new List<int>();
foreach (var grade in grades)
{
if (grade < 38) RoundedResult.Add(grade);
else RoundedResult.Add(AfterRounded(grade));
}
return RoundedResult;
}
/// <summary>
/// If the difference between the <paramref name="grade"/> and the next multiple of 5 is less than 3,
/// round <paramref name="grade"/> up to the next multiple of 5.
/// </summary>
/// <param name="grade"></param>
/// <returns>The <paramref name="grade"/> after rounding.</returns>
private static int AfterRounded(int grade)
{
var diff = 5 - (grade % 5);
return (diff < 3) ? grade + diff : grade;
}
}
}