Help on my Card class please.
Hey guys, I was wondering if you guys could lookover my Card class.
Would this be sufficient enough to implement a card drawing game?
public class Card
private int value;
private String suit;
public Card (int val, String cardSuit)
value = val;
suit = cardSuit;
"Everything in a web browser."
I'd think you at least need getters and of course there's the Deck class that's a collection of Cards.
Agreed, getters and setters will need to be added. You may want to break it into three variables.
- type (1 - 10, Jack, King, etc) (there must be a better word?)
Also, override toString() to provide a sentance when the user wants to print the Card.
public String toString()
return getType() + " of " + getSuit() + "'s";
I'm not sure setters are needed. (Or do you Aussies get out your Sharpies and rework your deck of cards every so often?)
lol. Of coarse.
I think setters are a good alternative to passing variables in the constructor. It may not be needed for this example, but still conforms to standards.
Bueza, You can setup a default constructor that takes no parameters.
In fact, if you want use those Cards as JSP page scope beans then you'll HAVE to set up setters and an empty constructor.
I don't mind breaking some standards if the behaviour of the object calls for it. Sometimes we code a default constructor and make it private to eliminate the possibility that it be "automagically" built by a JSP that should be receiving it ready to go.
Users Browsing this Thread
There are currently 1 users browsing this thread.
(0 members and 1 guests)