Created
October 19, 2023 12:58
-
-
Save alexaleluia12/4bf17b6552c6744111c6266085b1ccef to your computer and use it in GitHub Desktop.
Google PlayGround
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() { | |
printFinalTemperature(27.0, "celcius", "farenhit", celciusToFarenhit) | |
printFinalTemperature(350.0, "kelving", "celcius") {it - 273.15} | |
printFinalTemperature(10.0, "farenhit", "kelvin", farenhitToKelvin) | |
} | |
val celciusToFarenhit = { | |
celcius: Double -> | |
(9.0/5.0*celcius) + 32.0 | |
} | |
val farenhitToKelvin = { | |
farenhit: Double -> | |
(5.0/9.0)*(farenhit-32.0) + 273.15 | |
} | |
fun printFinalTemperature( | |
initialMeasurement: Double, | |
initialUnit: String, | |
finalUnit: String, | |
conversionFormula: (Double) -> Double | |
) { | |
val finalMeasurement = String.format("%.2f", conversionFormula(initialMeasurement)) // two decimal places | |
println("$initialMeasurement degrees $initialUnit is $finalMeasurement degrees $finalUnit.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment