Implement a class

Report a typo

Write a class LewisCarrollBook with custom getters and setters, which has three fields: name with the default value "", author with the default value Lewis Carroll, and price with the default value 0.

The main() function looks like this:

fun main() {
    val lewisCarrollBook = LewisCarrollBook()
    var bookName = lewisCarrollBook.name
    lewisCarrollBook.name = "Alice's Adventures in Wonderland"
    bookName = lewisCarrollBook.name
    var authorName = lewisCarrollBook.author
    var bookPrice = lewisCarrollBook.price
    lewisCarrollBook.price = 1500
}

And the output should be the following:

The name of the book is 
Now, a book called Alice's Adventures in Wonderland
The name of the book is Alice's Adventures in Wonderland
The author of the book is Lewis Carroll
Putting a new price...
The new price is 1500
Write a program in Kotlin
// write your class here
___

Create a free account to access the full topic