Solved

Java Enumerations

Posted on 2003-10-23
6
275 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
Facing this issue for maven proxy setting 2 20
Convert from a json string array to a Java object 3 51
Problem to Alipay 10 42
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…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 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