Danger level

Report a typo

Given an enumeration named DangerLevel.

Add an integer property to store the danger level and ascribe the number to each constant:

HIGH 3
MEDIUM 2
LOW 1

Also, you need to add the getLevel member function that returns the associated integer number.

After your modifications, the following code is to compile and to work correctly:

val high = DangerLevel.HIGH
val medium = DangerLevel.MEDIUM

println(high.getLevel() > medium.getLevel()) // true

You can't name the property level, because in this case the hidden getLevel() function (returns the value of the level property) automatically created. So, choose another name for the property.

Write a program in Kotlin
enum class DangerLevel {
HIGH,
MEDIUM,
LOW
}
___

Create a free account to access the full topic