You have a map with the names of buttons and corresponding font sizes and also a data class with default parameters. Write the body of the apply function so that your code could receive the name of a button from standard input, assign this value to the parameter text, and assign the corresponding value from map to the parameter textSize. After that, your code should print the new parameters to standard output like in the example. It's guaranteed that the input string will be contained in the map as key.
Scope functions: apply and also
Map of buttons
Report a typo
Sample Input 1:
ButtonSample Output 1:
New settings: TextField(text=Button, textSize=14, fontFamily=Roboto)Write a program in Kotlin
data class TextField(
var text: String = "Hello!",
var textSize: Int = 12,
var fontFamily: String = "Roboto"
)
fun main() {
val textField = TextField()
val valuesMap = mapOf<String, Int>(
"Cancel" to 12,
"Button" to 14,
"Submit" to 13
)
textField
.apply {
// Write your code here
}
.also { println("New settings: $it") }
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.