Click to See Complete Forum and Search --> : Enum problem


Steve25
08-02-2009, 06:31 PM
I can't seem to work out why this isn't working or how to get it to work. It doesn't seem to understand what Hearts and Two is. I'm trying to do this simple application just for practice here's the code:

class Blackjack
{
public static void main()
{
Card playerCard = new Card();
playerCard.suit = Hearts;
playerCard.rank = Two;
System.out.println(playerCard.rank);
}
}

class Card
{
public enum Suit
{
Hearts,
Diamonds,
Spades,
Clubs
}

public enum Rank
{
Ace,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King
}

Suit suit;
Rank rank;
}

SureshReddy
08-03-2009, 02:05 AM
//playerCard.suit = Hearts; replace this with
playerCard.suit=Card.Suit.Hearts;

//and
// playerCard.rank = Two; with

playerCard.rank=Card.Rank.Two;

//enums can be declared as their own class, or enclosed in another class, and //that the syntax for accessing an enum's members depends on where the enum //was declared.