user2791519
user2791519

Reputation: 1

Creating a class to represent a playing card

I am trying to make a Card class to represent playing cards. The code on the bottom runs the code on the top. I just need help getting started. I'm not exactly sure how to though. How would I create the constructor for this class also?

public class Card
{
  public static final String FACES[] = {"ZERO","ACE","TWO","THREE","FOUR",
  "FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"};

//instance variables
    //String suit
    //int face

//constructors


// modifiers
    //set methods


//accessors
    //get methods


//toString

 }

public class CardRunner
{
    public static void main( String args[] )
    {
    Card one = new Card("SPADES", 9);
    out.println(one.getSuit());
    out.println(one.getFace());

    Card two = new Card("DIAMONDS", 1);
    out.println(two);
    two.setFace(3);
    out.println(two);

    Card three = new Card("CLUBS", 4);
    out.println(three);

    Card four = new Card("SPADES", 12);
    out.println(four);

    Card five = new Card("HEARTS", 12);
    out.println(five);
}
}

Upvotes: 0

Views: 830

Answers (1)

Prasad Kharkar
Prasad Kharkar

Reputation: 13556

I think you should use an enum here for PlayingCard because all are constants and you can override toString to give meaningful representation.

If you create enum, you do not have to create objects explicitly and can use enum constants whenever you want to use. You can read a nice tutorial on why to use enumerations in java

Upvotes: 4

Related Questions