Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features

Standard delegates

Follow the map!

Report a typo

Write a class Employee that takes a parameter of type MutableMap as a constructor and has properties for name, age, and salary. The values of these properties should be stored in a map instead of separate fields for each property.

name is of type String, age is Int, and salary is Double.

Sample Input 1:

Ahmed-34-800.00

Sample Output 1:

Name: Ahmed
Age: 34
Salary: 800.0
Write a program in Kotlin
class Employee(...) { // Add the correct constructor

// Write your code here

}

// Do not change the code below
fun main() {
val (n, a, s) = readln().split("-")
val employee = Employee(mutableMapOf(
"name" to n,
"age" to a.toInt(),
"salary" to s.toDouble()
))

println("Name: ${employee.name}")
println("Age: ${employee.age}")
println("Salary: ${employee.salary}")
}
___

Create a free account to access the full topic