?
Solved

Java Enumerations

Posted on 2003-10-23
6
Medium Priority
?
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 388 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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