Program for Blackjack-initialize the deck

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amestrada113
    New Member
    • Nov 2014
    • 1

    Program for Blackjack-initialize the deck

    Code:
    public Deck()
    	{ 
    		cards=new Card[52]; 
    		String [] suits = {"spades", "hearts", "clubs", "diamonds"}; 
    		int [] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; 
    		for (int j=0; j<values.length; j++)
    		{
    			for (int i=0; i<suits.length; i++)
    			{
    				cards [j*4+i] = new Card (values[j], suits[i]); 
    			}
    		}//close for loop  
    	}//close method
    Hi! I am doing a project for a class that has me write a program to play Blackjack. I have all of the coding done but when I run the program I only Aces for my values while I do get different suits. Can anyone help me and please tell me why this code doesn't work to instantiate a deck of cards? When I try to print out what this method gives me I get: [LCard;@1aa8c488
    Last edited by Rabbit; Nov 13 '14, 06:00 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    The problem could be with the Card function. But I can't be sure, there's no code for it.

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      what this method gives me I get: [LCard;@1aa8c488
      First, cards is an array. So you should print out cards[0], cards[1] etc. or just use:
      Code:
      System.out.println(Arrays.asList(Arrays.asList(cards)));
      I hope you have added a toString method to your Card-class which prints the card inner class variables (suit and value), so that you can see them printed out with the command above.

      Comment

      Working...