Posted: 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
Hikaru79
Posted: 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
Posted: 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
Posted: 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
Posted: Sat Jan 22, 2005 7:39 pm Post subject: (No subject)
I've already told you why
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
Posted: 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 .
wtd
Posted: Sat Jan 22, 2005 7:49 pm Post subject: (No subject)
Hikaru79 wrote:
I've already told you why
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
Posted: 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
Neo
Posted: 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
Posted: Sun Jan 23, 2005 3:44 pm Post subject: (No subject)