/    Sign up×
Community /Pin to ProfileBookmark

Help on my Card class please.

Hey guys, I was wondering if you guys could lookover my Card class.

[code]
public class Card
{
private int value;
private String suit;

public Card (int val, String cardSuit)
{
value = val;
suit = cardSuit;
}
}
[/code]

Would this be sufficient enough to implement a card drawing game?

to post a comment
Java

5 Comments(s)

Copy linkTweet thisAlerts:
@ray326Nov 18.2004 — I'd think you at least need getters and of course there's the Deck class that's a collection of Cards.
Copy linkTweet thisAlerts:
@buntineNov 19.2004 — Agreed, getters and setters will need to be added. You may want to break it into three variables.

  • - suit

  • - type (1 - 10, Jack, King, etc) (there must be a better word?)

  • - value


  • Also, override toString() to provide a sentance when the user wants to print the Card.
    <i>
    </i>public String toString()
    {
    return getType() + " of " + getSuit() + "'s";
    }

    Regards.
    Copy linkTweet thisAlerts:
    @ray326Nov 20.2004 — I'm not sure setters are needed. (Or do you Aussies get out your Sharpies and rework your deck of cards every so often?) ?
    Copy linkTweet thisAlerts:
    @buntineNov 20.2004 — 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.

    Regards.
    Copy linkTweet thisAlerts:
    @ray326Nov 20.2004 — 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.
    ×

    Success!

    Help @BuezaWebDev spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.22,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...