A different formatter?

Report a typo

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.

Sample Input 1:

kotlin

Sample 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()
}
___

Create a free account to access the full topic