doc_ufo
asked on
compiler unable to find variable
Hi,
I have a little problem in my class, the compiler is unable to find the variable "dealt" although it is declared properly.
class Hand
{
public Hand(){
}
public Card dealHand(Pack pack){
Card hand[] = new Card[5];
for ( int count = 0; count < hand.length; count++ ) {
Card dealt = pack.dealCard();
if ( dealt != null ) {
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else {
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl e cards to continue" );
return null;
}
}
return dealt;
}
}
The error message:
Compiling C:\JPadPro\Documents\Ide\P okerTester \Hand.java
C:\JPadPro\Documents\Ide\P okerTester \Hand.java :40: cannot resolve symbol
symbol : variable dealt
location: class Hand
return dealt;
Any one can point out where i've gone wrong?
I have a little problem in my class, the compiler is unable to find the variable "dealt" although it is declared properly.
class Hand
{
public Hand(){
}
public Card dealHand(Pack pack){
Card hand[] = new Card[5];
for ( int count = 0; count < hand.length; count++ ) {
Card dealt = pack.dealCard();
if ( dealt != null ) {
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else {
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl
return null;
}
}
return dealt;
}
}
The error message:
Compiling C:\JPadPro\Documents\Ide\P
C:\JPadPro\Documents\Ide\P
symbol : variable dealt
location: class Hand
return dealt;
Any one can point out where i've gone wrong?
You could do us and yourself a favour by beginning to type your code a bit formatted;
errors like these will show up sooner:
class Hand
{
public Hand()
{
}
public Card dealHand(Pack pack)
{
Card hand[] = new Card[5];
for(int count = 0; count < hand.length; count++ )
{
Card dealt = pack.dealCard();
if(dealt != null )
{
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else
{
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl e cards to continue" );
return null;
}
}
return dealt;
}
}
Now it's obvious that 'dealt' and 'i' are only valid within the scope of the for()
;JOOP!
errors like these will show up sooner:
class Hand
{
public Hand()
{
}
public Card dealHand(Pack pack)
{
Card hand[] = new Card[5];
for(int count = 0; count < hand.length; count++ )
{
Card dealt = pack.dealCard();
if(dealt != null )
{
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else
{
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl
return null;
}
}
return dealt;
}
}
Now it's obvious that 'dealt' and 'i' are only valid within the scope of the for()
;JOOP!
>> Now it's obvious that 'dealt' and 'i' are only valid within the scope of the for()
'dealt' and 'count'
________
radarsh
'dealt' and 'count'
________
radarsh
You are right.
;JOOP!
;JOOP!
Still not compilable unfortunately. Should be
public Card dealHand(Pack pack)
{
Card hand[] = new Card[5];
Card dealt = null;
for(int count = 0; count < hand.length; count++ )
{
dealt = pack.dealCard();
if(dealt != null )
{
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else
{
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl e cards to continue" );
return null;
}
}
return dealt;
}
public Card dealHand(Pack pack)
{
Card hand[] = new Card[5];
Card dealt = null;
for(int count = 0; count < hand.length; count++ )
{
dealt = pack.dealCard();
if(dealt != null )
{
hand[ count ] = dealt;
System.out.println("dealt = " + dealt);
}
else
{
System.out.println("NOT ENOUGH CARDS TO DEAL" );
System.out.println("Shuffl
return null;
}
}
return dealt;
}
>>return null;
can be removed too
can be removed too
ASKER
>> public Card dealHand(Pack pack)
>> {
>> Card hand[] = new Card[5];
>> Card dealt = null;
>>
>> for(int count = 0; count < hand.length; count++ )
>> {
>> dealt = pack.dealCard();
>>
>> if(dealt != null )
>> {
>> hand[ count ] = dealt;
>> System.out.println("dealt = " + dealt);
>> }
>> else
>> {
>> System.out.println("NOT ENOUGH CARDS TO DEAL" );
>> System.out.println("Shuffl e cards to continue" );
>> }
>> }
>> return dealt;
>> }
I've tried this and the compiler now gives me this error:
java.lang.NoSuchMethodErro r: Hand.dealHand(LPack;)Ljava /lang/Stri ng;
at Dealer.Deal(Dealer.java:15 )
at PokerTester.main(PokerTest er.java:12 )
the Dealer.Deal method is just to call out the dealhand method.
>> {
>> Card hand[] = new Card[5];
>> Card dealt = null;
>>
>> for(int count = 0; count < hand.length; count++ )
>> {
>> dealt = pack.dealCard();
>>
>> if(dealt != null )
>> {
>> hand[ count ] = dealt;
>> System.out.println("dealt = " + dealt);
>> }
>> else
>> {
>> System.out.println("NOT ENOUGH CARDS TO DEAL" );
>> System.out.println("Shuffl
>> }
>> }
>> return dealt;
>> }
I've tried this and the compiler now gives me this error:
java.lang.NoSuchMethodErro
at Dealer.Deal(Dealer.java:15
at PokerTester.main(PokerTest
the Dealer.Deal method is just to call out the dealhand method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks alot. The error was fixed after i recompiled all my files!
:-)
;JOOP!