I am new to Java and I am struggling to get my Enumeration to work. I am working in BlueJ and I have 2 classes (trying to build a game of solitaire). my first class is called Card and inside this class I have an enumeration called Suit. My other class is Deck and I am trying to call the enumeration from this class. My problem is in the for loop for deck where I have declared Suit suit. It does not recognize the class Suit.
My code is below, if anyone can tell what I am doing wrong... it would be much appreciated. Thanks!
public class Deck
{
private Bag<Card> cardBag = new Bag<Card>();
public Deck()
{
for(Suit suit : Suit.values())
{
Card card= new Card (suit, 5);
}
}
//
public class Card
{
public enum Suit
{
H, S, C, D
}
private Suit suit;
private int valueOfCard;
public static final int ACE = 1;
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;
public Card(int valueOfCard, Suit suit)
{
this.valueOfCard= valueOfCard;
this.suit=suit;
}
}
There are at least two possible solutions here:
Place the Suit
enumeration in its own file.
Access Suit
with its fully qualified name in other classes. That is use Card.Suit
, rather than just Suit
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With