I'm trying to create a hierarchy type system using an Enum. I've never used an Enum before.
This method always returns Peasant. I think it's because I am using "this" incorrectly, or maybe I am misunderstanding enums altogether.
public enum Rank {
PEASANT,
TRADER,
SQUIRE,
MERCHANT,
KNIGHT,
NOBLE,
KING;
public Rank getNextRank() {
switch (this) {
case PEASANT:
return SQUIRE;
case SQUIRE:
return KNIGHT;
case KNIGHT:
return NOBLE;
case NOBLE:
return KING;
case KING:
return PEASANT;
}
return PEASANT;
}
}
(I realize that the KING case isn't necessary, but I like it for readability)
I would like Rank.PEASANT.getNextRank()
to return Rank.SQUIRE
and Rank.NOBLE.getNextRank()
to return Rank.KING
, etc.