Link to home
Start Free TrialLog in
Avatar of Mixolydian
Mixolydian

asked on

Java Enumerations

Okay. I have done this in C++, but I don't think there's a way to do enumerations in java. Here's the problem: I'm making a card game, and there are 2 enums- 1 for suit and one for rank.
The C++ code looked like this:

typedef enum {carderror = -1, ace = 1, two, three, four, five, six, seven, eight, nine, ten, jack = 11, queen, king} rank;
typedef enum {suiterror = -1, hearts = 1, diamonds, clubs, spades} suit;

but what is the java equivalent to this? Because they both have to be used in if and switch statements.
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

There is no direct equivalent in java for enum.

Read here:
http://www.cuj.com/documents/s=8059/cuj9811bridges/
Avatar of tomboshell
tomboshell

Take a look at the colletions package in java.util.  You can do alot there like using an ArrayList, Vector to perform similar actions.  Or you could just simply create an array of objects (either Strings or create your own class for a card) and then cycle through the cards array.  
ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Java 1.5 will have c-like enums, but it probably won't be released for another 6 months or so.
Avatar of Mick Barry
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept StillUnAware's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

objects
EE Cleanup Volunteer