Created
March 19, 2021 12:47
-
-
Save AbGhost-cyber/5b66ff84557031c859a675a1487872cd to your computer and use it in GitHub Desktop.
this assignment is called parking fee
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
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