Hi, I have an interesting problem on my hands here. When I define the method :
I then get this javac error :
But if I add a object to the method to look like this :
Then I get this error :
I'm not sure what to do next?
***********************************************************
Here is what my classes look like :
**********************************************************
Code:
public Card addCardBackInHand()
{
return (Card)hand.push();
}
I then get this javac error :
Code:
C:\java\War>javac TryDeal.java
.\Hand.java:30: push(java.lang.Object) in java.util.Stack cannot be applied to (
)
return (Card)hand.push();
^
1 error
But if I add a object to the method to look like this :
Code:
public Card addCardBackInHand()
{
return (Card)hand.push(card);
}
Then I get this error :
Code:
C:\java\War>javac TryDeal.java
.\Hand.java:30: cannot resolve symbol
symbol : variable card
location: class Hand
return (Card)hand.push(card);
^
1 error
I'm not sure what to do next?
***********************************************************
Here is what my classes look like :
Code:
import java.util.*;
class Hand
{
private Stack hand = new Stack();
public void add(Card card)
{
hand.push(card);
}
// This method pulls a single card from the Hand.
public Card getCard()
{
return (Card)hand.pop();
}
public Card addCardBackInHand()
{
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();
System.out.println("\nYour hand is"+yourCard);
System.out.println("\nMy hand is"+myCard);
}
}