Created
March 30, 2020 06:56
-
-
Save xuhaibahmad/e9e1a98d78d15317c5270f857924de3e to your computer and use it in GitHub Desktop.
This file contains 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