As I was typing away an example for some work, I came across a syntax error with the 'getRandomInt()' method.
When the method was a 'void' method, the latter 'addObject()' method would not accept the 'getRandomInt' method as it was... classified as void (I guess thats how to word it). As I had not practised nit methods before, I thought I would set the 'getRandomInt()' as an int method instead of void and thats where I came across an error suggesting the 'getRandomInt()' method was incomplete even with closed brackets...
Any ideas how to fix this syntax error? Am I missing a whole different level of understanding in order to utilise classifying a method as an int method? Any fixes would be appreciated thank you!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 600 , 400 , 1 ); createAnimals(); } public int getRandomInt( int max) { int randomInt = Greenfoot.getRandomNumber(max); } private void createAnimals() { int count = 0 ; addObject( new Snake(), 295 , 190 ); if (count >= 10 ) { addObject( new Camel(), getRandomInt( 599 ), getRandomInt( 399 ) ); } } |