In what manner we can use enums ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

In what manner we can use enums ?

how we can use enums in our program

13th May 2017, 1:00 PM
Vishal
Vishal - avatar
2 Answers
13th May 2017, 1:43 PM
Tashi N
Tashi N - avatar
0
class Main { public static void main(String[] args) { Player player1 = new Player(Difficulty.EASY); Player player2 = new Player(Difficulty.MEDIUM); Player player3 = new Player(Difficulty.HARD); } } enum Difficulty { EASY(3000), MEDIUM(2000), HARD(1000); public final int bullets; private Difficulty(int bullets) { this.bullets = bullets; } } public class Player{ Player(Difficulty diff){ //your code goes here int bullets = diff.bullets; /* switch (diff) { case EASY: bullets = 3000; break; case MEDIUM: bullets = 2000; break; case HARD: bullets = 1000; break; } */ System.out.format("You have %d bullets", bullets); } }
21st Jan 2021, 12:38 AM
David Ordás
David Ordás - avatar