java - How do I write a constructor that initializes 52 card objects -


this need do:

this constructor initializes deck 52 card objects, representing 52 cards in standard deck. cards must ordered ace of spades king of diamonds.

here attempt @ it:

private card[] cards; string suit, card; private final int deck_size = 52;  public deck()  {     cards = new card[deck_size];     string suit[] = {"spades", "hearts", "clovers", "diamonds"};     string card[] = {"ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "joker", "queen", "king"};     (int c = 0; c<13; c++)         (int s = 0; s<4; s++)         {             cards.equals(new card(suit, card));          }    } 

it giving me error part "(new card(suit, card));" saying constructor card(string[], string[]) undefined. im not sure if allowed add constructors. code written include card(int, int) though.

ok this? work?

public class deck {      private card[] cards;     int value, suit;     private final int deck_size = 52;      public deck()      {         //1 = ace, 11=joker, 12=queen, 13=king         //1 = spades, 2 = hearts, 3 = clovers, 4 =diamonds         cards = new card[deck_size];         int suit[] = {1, 2, 3, 4};         int card[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};         (int c = 0; c<13; c++)             (int s = 0; s<4; s++)             {                 cards.equals(new card(suit[s], card[c]));              }          } 

maybe this:

cards = new card[deck_size]; string suits[] = {"spades", "hearts", "clovers", "diamonds"}; string cards[] = {"ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "joker", "queen", "king"};  int cardindex = 0; (string suit : suits) {     (string card : cards) {         cards[cardindex] = new card(suit, card);         cardindex++;     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -