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
9 odpowiedzi
+ 10
What is the problem, it's working as expected!
+ 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;
}
}
}
+ 3
I didn't see any error or missing in ur code.
Could u pls describe ur expectation with ur code
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"
0
Alphin K Sajan ,Aakaanksha 💕 ,Thomas Expected output is 2000 3000 3000
But mine showing 3000 2000 1000
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
0
Thomas I did what i supposed to.I dont think the tests are mis spelled.
What if its something else.
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
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);
}
}