I am new to programming and Java and am currently learning enum types.
I have created an enum type Card
which stores the value of each card in a deck of cards, for example Two = 2, Three = 3 ... Ace = 11. Each picture card has the same value, 10.
I am trying to implement a method getPrevious()
, that will return the previous enum value in the list. For example if the method is called on SIX
, it will return FIVE
, and when called on TWO
will return ACE
. However i am struggling to figure out a way to do so.
Below you can see the current code that i have written, any help or tips on how to implement the method getPrevious()
would be incredibly helpful.
public class EnumPractice {
public enum Card {
TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8),
NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11), ;
private int value;
private Card card;
Card(int value){
this.value = value;
}
public int getValue(){
return value;
}
public String toString(){
return "The value of this card is: " + value;
}
}
public static void main(String[] args) {
System.out.println(Card.ACE.getValue());
}
}