• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with syntax and concept for Mancala  RSS feed

 
Matthew Moreno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having trouble with my mancala game code. The entire code is much longer but in the interest of being more eye appealing, i shortened it greatly. In the module PlayersTurn, im trying to actually be able to play the game but im having a hard time setting it up and finding the syntax for the code. I tried setting POCKETS[0] = to a string. The reason is so when the program asks the user what pocket they want to play the program reads their input and then play the pocket. When i tried to set POCKETS[0] = string 0 i got a compile error. Am i going about this the right way? is there an easier way to be able to let the user play a pocket? anything would help. Thanks
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch.

Please use Java naming standards, it makes it so much easier for other people to read your code. Method and variable names should start with lower case letters, class names with upper case, only constants should be all upper case etc.
Also when providing code please make sure it is meaningful ie it compiles and runs.

POCKETS is an int array so you can only assign int values to it. If the user inputs a String then you have to convert it to an int. Scanner has methods to do this as does the Integer class but as you are using a Scanner use it to get the input as anint.

BTW why are all your methods static?
 
Matthew Moreno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im a beginning programmer and we've always been taught to make methods static. So by making it an int ill be able to call POCKETS and initiate turns? like this?

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it compile?
It's generally quicker to try it yourself than ask here and wait for a reply.

But as you have asked the answer is no. You don't use the 'int' keyword unless you are declaring a variable as type int. Use:

This will allow the code to compile, whether it makes your program work or not depends on the rest of your code.


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!