How to fix this setter & getter?

Please help me to finish my online learning academy. The question is as follows:

TODO 1:

Complete the code in the Cat class with the following provisions:
-Create a getter setter function for the Sleep property in which there is a function for printing text:

The getter/setter function is invoked

-Add the code in the toSleep() function to print the text:

[$name], sleep!

If sleep is true and the text is:

Name, let’s play!

If sleep is false.

You can see the Kotlin code that I’ve created to fix it in the screenshot which i attached. Thank. Hope your day is fun!

I don’t think just showing you the anser will help you. You say that this is part of an online learning academey. In that case I would write to the person teaching and ask questions.
It looks like the online course is not good or you aren’t really participating and just handing in basic solutions from the internet. I mean this is the 3rd post from you asking for a solution in 4 days. You aren’t asking questions about how to solve something, it looks like you are just interested in the solution, which won’t help you understand the problem. Also those questions seem to handle basic parts of kotlin so you should look into those again. Either as part of you online academy or by using other resources like:
https://kotlinlang.org/docs/books.html
https://kotlinlang.org/docs/tutorials/
https://kotlinlang.org/docs/reference/
https://kotlinlang.org/docs/reference/basic-syntax.html
https://www.google.com/search?q=kotlin+tutorial+for+beginners


As for the current question, I can’t help you. I don’t understand what they want you to do, but I suspect that it might be a translation problem. The only part I can help you with is that the getter and setter for sleep shouldn’t be private. Otherwise you won’t be able to call them from the main function.

2 Likes