0
public void createDeck() {
    k=0;
    cards=new Card[52];

    for (i=0;i<4;i++) {
        for (j=0;j<13;j++){
            cards[k]=new Card(i,j);
            k++;                
        }
    }
}

public void shuffleDeck(int m){
    Random random = new Random(); 
    Card cardTemp;
    for(i=0;i<m;i++){
        k=random.nextInt(52);
        cardTemp=cards[i%52];
        cards[i%52]=cards[(i+k)%52];
        cards[(i+k)%52]=cardTemp;
    }                   
}

Hello. I want to take i and j which is in

cards[k]=new Card(i,j);

Because i want to show rank an suit by taking this i and j:

    public Card(int suit,int rank){
        this.rank=rank;
        this.suit=suit;
    }

  private final static String[] suits = { "Hearts", "Spades", "Diamonds", "Clubs" };

   private final static String[] ranks  = { "Ace", "2", "3", "4", "5", "6",
       "7", "8", "9", "10", "Jack", "Queen", "King" };

In another class,

deck=new Deck();
deck.createDeck();
deck.shuffleDeck(111);

Should i use another array? I am really confused. I want to give the screen, for example ace hearts after shuffling.

4
  • 1
    Not sure what you meant Commented Aug 21, 2013 at 8:50
  • You likely won't need new arrays, but I'm unsure what you're asking. Do you want to find the card which is in k position? Commented Aug 21, 2013 at 8:51
  • I want to give the screen, for example ace hearts. I know k in cards[k]=new Card(i,j); but i cant take i j here. Commented Aug 21, 2013 at 8:53
  • OK, then @NoIdeaForName's answer should be helpful. Commented Aug 21, 2013 at 8:55

1 Answer 1

4

it is not clear what are you asking, but i can guess that you want is when you draw a card from the shuffled deck you'll be able to see it's rank and suit. right?

then the answer is to add 2 methods to Card class:

public int getSuit()
{
   return suit;
}

public int getRank()
{
   return rank;
}

and then, when you draw a card:

Card c = cards[k];
int cSuit = c.getSuit();
int cRank = c.getRank();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.