0

I have this problem in enums

Under the java course ,the enum practice section is not working as i expected. What am i missing here? https://code.sololearn.com/c8rqhk3a0ys9/?ref=app

23rd Oct 2020, 3:07 PM
sid
sid - avatar
9 odpowiedzi
+ 10
What is the problem, it's working as expected!
23rd Oct 2020, 3:21 PM
Aakaanksha 💕 [TheBraveCoders]
Aakaanksha 💕 [TheBraveCoders] - avatar
+ 7
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, MEDIUM, HARD } public class Player{ Player(Difficulty diff){ //your code goes here switch(diff) { case EASY: System.out.println("You have 3000 bullets"); break; case MEDIUM: System.out.println("You have 2000 bullets"); break; case HARD: System.out.println("You have 1000 bullets"); break; } } }
3rd Nov 2021, 12:21 PM
prabodha lahiru
prabodha lahiru - avatar
+ 3
I didn't see any error or missing in ur code. Could u pls describe ur expectation with ur code
23rd Oct 2020, 3:28 PM
Alphin K Sajan
Alphin K Sajan - avatar
0
Check your output. It should be as shown in the task: EASY => "You have 3000 bullets" MEDIUM => "You have 2000 bullets" HARD => "You have 1000 bullets"
23rd Oct 2020, 3:56 PM
Coding Cat
Coding Cat - avatar
0
Alphin K Sajan ,Aakaanksha 💕 ,Thomas Expected output is 2000 3000 3000 But mine showing 3000 2000 1000
23rd Oct 2020, 4:26 PM
sid
sid - avatar
0
Ok. But for Easy, Medium, Hard, you must get 3000 2000 1000 Maybe the test is broken, or you have to change the Difficulty for the players to medium easy easy. And add the Text to the output
23rd Oct 2020, 4:57 PM
Coding Cat
Coding Cat - avatar
0
Thomas I did what i supposed to.I dont think the tests are mis spelled. What if its something else.
23rd Oct 2020, 5:02 PM
sid
sid - avatar
0
sid I got it now. Attached code is the spoiler! The list of expected outputs can be scrolled. There is a 4. line given! The difficultes for Player 1-3 are wrong for the expected output. So I have changed the difficultes for Player 1-3 to get expected output. And I have added a 4. player with Difficulty to get the last expected output. Then does it work. https://code.sololearn.com/cIxb9sSgCrQN/?ref=app
24th Oct 2020, 1:09 PM
Coding Cat
Coding Cat - avatar
0
Or.... 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:32 AM
David Ordás
David Ordás - avatar