473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Program for Blackjack-initialize the deck

Expand|Select|Wrap|Line Numbers
  1. public Deck()
  2.     { 
  3.         cards=new Card[52]; 
  4.         String [] suits = {"spades", "hearts", "clubs", "diamonds"}; 
  5.         int [] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; 
  6.         for (int j=0; j<values.length; j++)
  7.         {
  8.             for (int i=0; i<suits.length; i++)
  9.             {
  10.                 cards [j*4+i] = new Card (values[j], suits[i]); 
  11.             }
  12.         }//close for loop  
  13.     }//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
Nov 12 '14 #1
2 1715
Rabbit
12,516 Expert Mod 8TB
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.
Nov 13 '14 #2
chaarmann
785 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Nov 17 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
6
by: Eric Lilja | last post by:
Hello! Consider this simple C program: #include <stdio.h> static void print_cards(const int); int main(void) { int deck = {{0}};
10
by: Arun Nair | last post by:
Can any one help me with this im not getting it even after reading books because there is not much of discussion anywhere a> Implement a calss that represents a playing card. The class should...
11
by: cazconv2007 | last post by:
hi i have homework due tomorrow been trying to do java homework all week and nothings happening really starting to stress out i dont understand what the program is meant to do or how to use three...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
32
by: falconsx23 | last post by:
I am making a game called Set, it is a card game: here is a brief description of the rules: The game of Set is played with 81 cards, each of which has 4 properties (number, pattern, color and...
6
by: kfansi | last post by:
Hello everybody, I know I'm really new to the site, but I really need your help. I've been developing a blackjack game over the last few days and I'm a bit stuck know. If you guys could help me...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.