Solved

Java Enumerations

Posted on 2003-10-23
6
270 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:Mixolydian
6 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 9607020
There is no direct equivalent in java for enum.

Read here:
http://www.cuj.com/documents/s=8059/cuj9811bridges/
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 9607023
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.  
0
 
LVL 14

Accepted Solution

by:
StillUnAware earned 97 total points
ID: 9607024
0
 
LVL 1

Expert Comment

by:tomangioletti
ID: 9608048
Java 1.5 will have c-like enums, but it probably won't be released for another 6 months or so.
0
 
LVL 92

Expert Comment

by:objects
ID: 10215098
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
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 52
servlet example 11 40
login form jsp example 2 24
JavaFX TableView not displaying correctly 3 16
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question