Creating a Car entity in a program

Report a typo

Your task is to complete a simple Kotlin program that models a Car entity. The Car object should have a constructor that takes three parameters - brand, model, and year, all of which should be initialized using named arguments during object creation. Also, each time a new Car object is created, it should print out a statement displaying the car's brand, model, and year. Fill the blanks in the code to make it work as expected.

Fill in the gaps with the relevant elements
 Car( brand: String, val model: String, val year: Int) {
     {
        println("Car brand: $brand, Model: $model, Year: $year")
    }
}
 main() {
    val car1 = Car(brand = "Toyota", model = "Corolla", year = 2020)
}
classvalinitfun

Create a free account to access the full topic