Build it all yourself

Report a typo

We have the following class:

class Cat(val name: String, val age: Int, val breed: String)

And the following function:

def showInfo(cat: Cat): String =
  s"""Your Cat information:
     |Name: ${cat.name}
     |Age: ${cat.age}
     |Breed: ${cat.breed}""".stripMargin

Change the code to turn showInfo into a class method.

Sample Input 1:

Cat("Bob", 2, "Scottish")

Sample Output 1:

Your Cat information:
Name: Bob
Age: 2
Breed: Scottish
Write a program in Scala 3
class Cat(val name: String, val age: Int, val breed: String)
___

Create a free account to access the full topic