Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Subroutines
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neo




PostPosted: Sat Jan 22, 2005 7:02 pm   Post subject: Subroutines

Why do I get an error at cardDraw in the subroutine? It says cannot resolve symbol.
code:

public class BlackJack{
       
        public static void main (String[]args){
                boolean[][] cardDrawn=new boolean[13][4];

        }//end of MAIN

        static int SELECT_CARD(int tempValue, int tempSuit){
                if (cardDraw[tempValue][tempSuit]=true){
                        return 0;
                }
        }

}//end of BlackJack class
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Sat Jan 22, 2005 7:07 pm   Post subject: (No subject)

Simply because the variable you declared is cardDrawn, but you CALL cardDraw with no 'n'.

But you'll still get an error. You need to tell the function what to return assuming the 'if' condition is false.

EDIT: Wait, I don't think it'll work anyway because cardDraw is declared inside main, so it's not global. There's quite a few things wrong with that code =P
Neo




PostPosted: Sat Jan 22, 2005 7:26 pm   Post subject: (No subject)

Ok so I declare it outside main to make it global? Now it says missing return statment and poiints to line 11...
BTW this is just a snipet of my code, I just need this part to compile correctly.

code:

public class BlackJack{
        boolean[][] cardDrawn=new boolean[13][4];
       
        public static void main (String[]args){
        }//end of MAIN

        public int SELECT_CARD(int tempValue, int tempSuit){
                if (cardDrawn[tempValue][tempSuit]=true){
                        return 0;
                }
        }
}//end of BlackJack class
wtd




PostPosted: Sat Jan 22, 2005 7:27 pm   Post subject: (No subject)

There are other problems. The array is declared locally within main. It cannot then be referenced in another method unless passed in as an argument.
Hikaru79




PostPosted: Sat Jan 22, 2005 7:39 pm   Post subject: (No subject)

I've already told you why Smile
Hikaru79 wrote:

But you'll still get an error. You need to tell the function what to return assuming the 'if' condition is false.


What will the method return if cardDrawn[tempValue][tempSuit]=false ? You need to give it a backup plan. Also, by convention, method names shouldn't be in all caps.
Neo




PostPosted: Sat Jan 22, 2005 7:44 pm   Post subject: (No subject)

Hikaru79 wrote:

But you'll still get an error. You need to tell the function what to return assuming the 'if' condition is false.


Thanks Hikaru, my eyes kinda jumped that line Laughing .
wtd




PostPosted: Sat Jan 22, 2005 7:49 pm   Post subject: (No subject)

Hikaru79 wrote:
I've already told you why Smile
Hikaru79 wrote:

But you'll still get an error. You need to tell the function what to return assuming the 'if' condition is false.


What will the method return if cardDrawn[tempValue][tempSuit]=false ? You need to give it a backup plan. Also, by convention, method names shouldn't be in all caps.


Nor should they include underscores.

Also

code:
cardDrawn[tempValue][tempSuit]=false


Will always return false. Perhaps you meant:

code:
cardDrawn[tempValue][tempSuit] == false
Neo




PostPosted: Sat Jan 22, 2005 10:06 pm   Post subject: (No subject)

wtd wrote:

code:
cardDrawn[tempValue][tempSuit]=false


Will always return false. Perhaps you meant:

code:
cardDrawn[tempValue][tempSuit] == false


Yea these little things catch me every time, I'm too used to turing.
Sponsor
Sponsor
Sponsor
sponsor
Neo




PostPosted: Sun Jan 23, 2005 1:33 pm   Post subject: (No subject)

If I declare a variable outside the main routine why won't it let me use it from inside the main routine? And why cant I call the funciton from within main? It says non-static method cannot be referenced from a static context.

EDIT: If I declare the variables and function as static I get no error... anyone care to explain why?
Hikaru79




PostPosted: Sun Jan 23, 2005 3:44 pm   Post subject: (No subject)

Do you understand the difference between static and non-static? Read here: http://leepoint.net/notes-java/20language/40methods/50static-methods.html
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: