Created
September 14, 2019 04:46
-
-
Save xuhaibahmad/0e4e36cfbdd19b39789ff4c1d88f4198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GradeCalculator { | |
var totalMarks = 0 | |
fun getGrade(obtainedMarks: Int, totalMarks: Int): String { | |
val percentage = getPercentage(obtainedMarks, totalMarks) | |
return when { | |
percentage >= 90 -> "A" | |
percentage in 80..89 -> "B" | |
percentage in 70..79 -> "C" | |
percentage in 60..69 -> "D" | |
else -> "F" | |
} | |
} | |
private fun getPercentage(obtainedMarks: Int, totalMarks: Int): Int { | |
return (obtainedMarks / totalMarks.toFloat() * 100).roundToInt() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment