Search code examples
javaclassenumsplaying-cards

Class for representing a card in Java?


I'm making a blackjack program in Java, and I was starting to write the class declaration for an object Card. Will this be sufficient, or are there some methods I should have that I'm glossing over?

public class Card {
    public int suit; //Value 1-4 to represent suit
    public int value; //Value 1-13 to represent value (i.e. 2, J)
    public Card(int suit, int value) {
        //Not yet implemented
    } 
}

Also, is there a good way to have an something like C++'s enum data structure in Java, because that would be nice for card names and suits?


Solution

  • public enum Suite {
        HEART, DIAMOND, CLUB, SPADE
    }
    public enum Value {
        TWO, THREE, ... , JACK, QUEEN, KING, ACE 
    }
    

    and the rest you can figure out.