• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java program help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a program for a blackjack game that uses arrays to shuffle cards and deal them to a player and dealer/ I am having a hard time retrieving the card value from one class to another. This is in the hand class which I want to use to retriev the card and then add the value of the cards together

public void gethand()
{

Shoe temp = new Shoe();
temp.getCard();
Deck = temp.Deck;

This is the class that is creating the card from the array

public static String getCard()
{
Index++;
InPlay[Index] = true;
return ShuffleDeck[Index];
}

Any help would be great Thanks.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't take my word for much as I've only been learning Java for a day or two, but maybe this would work?

Perhaps you could use two ArrayLists? One to hold the true deck and one to hold the shoe. If you make them integers your returns would be easier to handle I think.

import java.util*
public class BlackJack
{
private static int[] hearts = {1, 2, 3, ....};
// repeat for the other suits

private ArrayList<Integer> Deck = new ArrayList<Integer>();
private ArrayList<Integer> Shoe = new ArrayList<Integer>();

private void makeMyDeck()
// code I'm not really sure on here to populate the Deck with the four arrays and their indexes?

private void shuffleDeck()
{
// Do stuff here to populate Shoe randomly from Deck
}

public int dealTheCards()
{
// Code here to spit out the 0 index of Shoe to a Dealer object and a Player object, removing each element as it spits them out.
}

public int hitMe()
{
// Code here to spit out the 0 index of Shoe to the calling object, then remove that element.
}

public string getName()
{
// Code here to get the string name of the index value of each card, like "Ace", "two" and so on.

public void playGame()
{
// Put the game loop here
}
}

You can reference getName() to print out the text value of the cards, and keep the other returns integers to do all the math for the game loop.

Anyway, just my thoughts. Again, I'm still learning and very much new so there is probably a better way. Hope it helped a little, and hopefully someone who knows a lot more can give better details and/or a better way.

Nathan
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi


the statement temp.getCard() itself returns a string.
You don't have to write any other statements .

This will work fine :

String returnedValue = temp.getCard();
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic