Danger levels

Report a typo


You are given an enum named DangerLevel.

Add an integer field to store danger levels and match the number with each constant:

  • HIGH — 3
  • MEDIUM — 2
  • LOW — 1

You should also add the instance method getLevel that returns the associated integer number.

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

DangerLevel high = DangerLevel.HIGH;
DangerLevel medium = DangerLevel.MEDIUM;

System.out.println(high.getLevel() > medium.getLevel()); // true
Write a program in Java 17
enum DangerLevel {
HIGH,
MEDIUM,
LOW;
}
___

Create a free account to access the full topic