The Artima Developer Community
Sponsored Link

Java Answers Forum
syntax error using a method

3 replies on 1 page. Most recent reply: May 25, 2002 3:40 AM by Singh M.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
gemann

Posts: 2
Nickname: gemann
Registered: May, 2002

syntax error using a method Posted: May 24, 2002 11:03 PM
Reply to this message Reply
Advertisement
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();   
 public void 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
{
  public static void 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);
  }
}

*****************************************************

But I'm getting these 2 syntax errors and I'm not sure how to correct them.

C:\java\War>javac TryDeal.javaTryDeal.java:23: ')' expected Hand returnHand = myCard.addCardBackInHand(Card card);                                           ^


 TryDeal.java:23: cannot resolve symbolsymbol  : variable Cardlocation: class TryDeal Hand returnHand = myCard.addCardBackInHand(Card card);                                               ^2 errors


I would like to thank you in advance for assisting me with this problem.......gemann


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: syntax error using a method Posted: May 24, 2002 11:27 PM
Reply to this message Reply
the line...
Hand returnHand = myCard.addCardBackInHand(Card card);

should be...

Hand returnHand = myCard.addCardBackInHand(card);

gemann

Posts: 2
Nickname: gemann
Registered: May, 2002

Re: syntax error using a method Posted: May 25, 2002 12:06 AM
Reply to this message Reply
> 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

Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: syntax error using a method Posted: May 25, 2002 3:40 AM
Reply to this message Reply
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.

Flat View: This topic has 3 replies on 1 page
Topic: HELP ME PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Previous Topic   Next Topic Topic: Difference between ArrayList and Vector

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use