Mini Project: Grade Calculator
Build a small Kotlin program that calculates an average mark and determines a grade.
Kotlin Code
Study the example and understand each part.
fun calculateGrade(
average: Double
): String {
return when {
average >= 70 -> "A"
average >= 60 -> "B"
average >= 50 -> "C"
else -> "D"
}
}
fun main() {
val mathematics = 80
val science = 75
val english = 85
val average =
(mathematics +
science +
english) / 3.0
println("Average: $average")
println(
"Grade: ${calculateGrade(average)}"
)
}
Kotlin is commonly developed using Android Studio or IntelliJ IDEA. These examples can be used as a foundation for Android application development.
Key Concept
This project combines variables, functions, arithmetic and when expressions into one practical program.
Expected Output / Result
Average: 80.0 Grade: A
Finished this lesson?
Mark it complete to update your course progress.