aspose file tools*
The moose likes Beginning Java and the fly likes Java program help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java program help" Watch "Java program help" New topic
Author

Java program help

Lauren Kwiatek
Greenhorn

Joined: Dec 10, 2006
Posts: 1
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

Joined: Nov 26, 2006
Posts: 132
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


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Divya Shastry
Greenhorn

Joined: Dec 05, 2006
Posts: 11
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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java program help