Hi, I'm getting this error when I call :
myCard.addCardBackInHand(card);
this is the error I get:
these are some of my classes :
I tried to instanciate a new Card object :
Card card = new Card(); but I got these errors :
I need some help defining the card variable.....gemann
myCard.addCardBackInHand(card);
this is the error I get:
Code:
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
these are some of my classes :
Code:
import java.util.*;
class Hand
{
private Stack hand = new Stack();
public void add(Card card)
{
hand.push(card);
}
public Card getCard()
{
return (Card)hand.pop();
}
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();
}
Code:
class TryDeal
{
public static void main(String[] args)
{
CardDeck deck = new CardDeck();
deck.shuffle();
Hand myHand = deck.dealHand(5);
Hand yourHand = deck.dealHand(5);
Card myCard = (Card)myHand.getCard();
Card yourCard = (Card)yourHand.getCard();
Hand returnHand = myCard.addCardBackInHand(card);
System.out.println("\nYour hand is"+yourCard);
System.out.println("\nMy hand is"+myCard);
System.out.println("\nMy return hand is"+returnHand);
}
}
Code:
class Card implements Comparable
{
public Card(int value, int suit) throws IllegalArgumentException
{
if(value >= ACE && value <= KING)
this.value = value;
else
throw new IllegalArgumentException("Invalid card value");
if(suit >= HEARTS && suit <= SPADES)
this.suit = suit;
else
throw new IllegalArgumentException("Invalid suit");
}
public int compareTo(Object card)
{
if(this.suit != ((Card)card).suit)
return suit < ((Card)card).suit ? -1: 1;
else
if(this.value == ((Card)card).value)
return 0;
else
return value < ((Card)card).value ? -1 : 1;
}
public String toString()
{
String cardStr;
switch(value)
{
case ACE: cardStr = "A";
break;
case JACK: cardStr = "J";
break;
case QUEEN: cardStr = "Q";
break;
case KING: cardStr = "K";
break;
default: cardStr = Integer.toString(value);
break;
}
// Here we add the suit to the value of the card
switch(suit)
{
case CLUBS: cardStr += "C";
break;
case DIAMONDS: cardStr += "D";
break;
case HEARTS: cardStr += "H";
break;
case SPADES: cardStr += "S";
break;
}
return cardStr;
}
// Suit values
public static final int HEARTS = 0;
public static final int CLUBS = 1;
public static final int DIAMONDS = 2;
public static final int SPADES = 3;
// Card face values
public static final int ACE = 1;
public static final int JACK = 11;
public static final int KING = 12;
public static final int QUEEN = 13;
private int suit;
private int value;
}
I tried to instanciate a new Card object :
Card card = new Card(); but I got these errors :
Code:
C:\java\War>javac TryDeal.java
TryDeal.java:13: cannot resolve symbol
symbol : constructor Card ()
location: class Card
Card card = new Card();
^
TryDeal.java:24: cannot resolve symbol
symbol : method addCardBackInHand (Card)
location: class Card
Hand returnHand = myCard.addCardBackInHand(card);
^
2 errors
I need some help defining the card variable.....gemann