Hi, Looking for some advice. What I'm trying to code is a simple card game. Here are my classes :
import java.util.*;
class Hand
{
// stores the cards in the hand
private Stack hand = new Stack();
publicvoid add(Card card)
{
hand.push(card);
}
// This method pulls a single card from the Hand.
public Card getCard()
{
return (Card)hand.pop();
}
// This method puts the winners cards back into his
// hand
public Card addCardBackInHand(Card card)
{
return (Card)hand.push(card);
}
public String toString()
{
Iterator cards = hand.iterator();
StringBuffer str = new StringBuffer();
while(cards.hasNext())
str.append(" "+ (Card)cards.next());
return str.toString();
}
}
class TryDeal
{
publicstaticvoid main(String[] args)
{
CardDeck deck = new CardDeck();
deck.shuffle();
Hand myHand = deck.dealHand(5);
Hand yourHand = deck.dealHand(5);
// here I'm pulling a card out for one player
// and another player further down the road I
// will compare these two cards and the player
// with the highest value will win this round
Card myCard = (Card)myHand.getCard();
Card yourCard = (Card)yourHand.getCard();
// her I want the winner to place the two cards
// he won and put them back in his hand. the return
// Hand is just a temporary storage place so I can
// display the results to see if this method worked
Hand returnHand = myCard.addCardBackInHand(Card card);
System.out.println("\nYour hand is"+yourCard);
System.out.println("\nMy hand is"+myCard);
System.out.println("\nMy return hand
is"+returnHand);
}
}
> the line... > Hand returnHand = myCard.addCardBackInHand(Card > card); > > should be... > > Hand returnHand = myCard.addCardBackInHand(card);
Thanks Singh M. that takes care of one of the errors, but I'm still getting :
C:\java\War>javac TryDeal.java TryDeal.java:23: cannot resolve symbol symbol : variable card location: class TryDeal Hand returnHand = myCard.addCardBackInHand(card); ^ 1 error
That is because in the class TryDeal.java, you have not defined the variable card. Just instantiate a new one or whatever you logic demands and the error will go away.