Can someone please take a look at this for me. I have to create a program that models a simple card game. I have to shuffle the card and deal 1 card at a time and display the card that I have dealt. Not sure how to do this. The code I have is returning 00. I also have to declair a winner. I guess I need to do a nested for loop to check against suit and face of card right.(havent tried it yet). Looking for suggestions or directions in the correct place.
Thanks.

Recommended Answers

All 5 Replies

I did few small changes to your files

CARDS change in card constructor

public Card(int f, int s)
{
    // initialise instance variables
    face = f;
    suit = s;        //you had suit = SPADE
}

DECK change your constructor public Deck() (with 2 for loops) to a method to initialize cards, I call it public void setCards()

DRIVER use the new method setCards() before you suffle cards

if (choices[0].equals((String) selected))
{
            inDeck.setCards();
            inDeck.shuffle();
            System.out.println("card mixed");
            playCards();}

I would create random function to get my set of cards and check if these cards hasn't been dealt. So dealt cards should be store somewhere :?:

I'm now able to see the card. But it will not display different cards. I keep getting 12 3

Did you tried a random function as I sugested???

Not sure what you mean by creating a random fucntion. I moved the intialization of dealt to the deal method. Is it because I needs some kind of equals function?

I think I poineted you in wrong direction, you don't need random function that is useful dice games. Sorry my mistake. ;)
But you may want to create another array of type card to store data about cards which been used and should not be dealth again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.