473,403 Members | 2,284 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,403 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 1718
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.