Solved

Java Enumerations

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now