Skip to content

Instantly share code, notes, and snippets.

@AbGhost-cyber
Created March 19, 2021 12:47
Show Gist options
  • Save AbGhost-cyber/5b66ff84557031c859a675a1487872cd to your computer and use it in GitHub Desktop.
Save AbGhost-cyber/5b66ff84557031c859a675a1487872cd to your computer and use it in GitHub Desktop.
this assignment is called parking fee
fun main() {
var hours = 4.0
val fixedHours = 24.0
val flatFee = 15.0
val total: Double
val chargeAfterFiveHours = 0.5
val chargeBeforeFiveHours = 1
when {
hours > fixedHours -> {
var days = 0
var rem = 0.0
while (hours > fixedHours) {
days++
hours -= fixedHours
rem = hours
}
total = (days * flatFee) + (rem * chargeAfterFiveHours)
}
hours < fixedHours -> {
total = if (hours - 5 > 0) {
val remHours = hours - 5
5 + (remHours * 0.5)
} else {
chargeBeforeFiveHours * hours
}
}
else -> total = flatFee
}
println(total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment