Following the Formatter example in the theory topic, implement a different formatter (CharacterInfoFormatter), which adds information about the number of characters printed after printing a given string.
Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features
Delegate
A different formatter?
Report a typo
Sample Input 1:
kotlinSample Output 1:
kotlin [6 characters]Write a program in Kotlin
interface MyInterface {
fun print()
var msg: String
}
class MyImplementation : MyInterface {
override fun print() { println(msg) }
override var msg: String = "To be, or not to be, that is the question:"
fun updateMsg(newMsg: String) { msg = newMsg }
}
class CharacterInfoFormatter(base: MyInterface) : MyInterface by base {
var start: String = ""
var end: String = ""
override fun print() {
// Your code here
}
}
fun main() {
val line = readln()
val a = MyImplementation()
a.updateMsg(line)
val delegate = CharacterInfoFormatter(a)
delegate.print()
}
___
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.