I wish to write a method that can return the difference in value of 2 cards. Im confused as I\'m learning enums and not sure of the most efficient way to implement it.
public enum Rank {ACE(1), TWO(2); /* obviously add the other values*/
private int value ;
Rank(int value){
this.value = value;
};
public int getValue(){
return this.value;
}
public int calcDifference(Rank rank){
return getValue() - rank.getValue();
}
};
which can then be called like so :
Rank rankAce = Rank.ACE;
System.out.println(rankAce.calcDifference(Rank.TWO));
You could remove the int value and just use ordinal, but this way gives you a bit of flexibility.