I'm sure there is already an answer for this, but I'm very new and a lot of the answers I found look overly complicated and well past my experience as a programmer.
I created a class with a method, I wish to call on that method to display after it promts the user for input. I know where to call on the method. But don't know how to in kotlin. PLEASE HELP!
Here's my code
fun main() {
println("Enter degrees in Fahrenheit")
}
class ComputeMethods(){
fun tempConversion(degreesF: Double){
var degreesF = readln().toDouble()
var degreesC = (degreesF - 32.0) * 5.0 / 9.0;
var conversion = "$degreesF degrees Fahrenheit = $degreesC degrees Celsius"
println(conversion)
}
}
CodePudding user response:
It's better to read user input inside main()
and pass it to the method
fun main() {
println("Enter degrees in Fahrenheit")
ComputeMethods().tempConversion(readln().toDouble())
}
class ComputeMethods(){
fun tempConversion(degreesF: Double){
var degreesC = (degreesF - 32.0) * 5.0 / 9.0;
var conversion = "$degreesF degrees Fahrenheit = $degreesC degrees Celsius"
println(conversion)
}
}