This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java program help

 
Lauren Kwiatek
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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
 
Divya Shastry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic