This site requires JavaScript, please enable it in your browser!
Greenfoot back
DocWhiskey
DocWhiskey wrote ...

2016/11/17

Greenfoot Chapter 6 Drill and Practice

DocWhiskey DocWhiskey

2016/11/17

#
Hey this is my first time posting so i am not really sure what the rules are but maybe someone can help me here, I am trying to do the drill and practice at the end of Chapter 6 which works on the Bubble scenario and for some reason i am stuck on Exercise 6.28, it calls for making a private method for the world called setup and naturally i attempt the import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * A bit of empty space for bubbles to float in. * * @author Michael Kölling * @version 1.0 */ public class Space extends World { /** * Create Space. Make it black. */ public Space() { super(900, 600, 1); getBackground().setColor(Color.BLACK); getBackground().fill(); } private int setup() } does not work either, is their something i am missing?
Super_Hippo Super_Hippo

2016/11/17

#
Change this...
1
private int setup()
...to...
1
2
3
4
private void setup()
{
    //some code... adding objects and so on
}
...and add the a method call in the constructor:
1
setup();
DocWhiskey DocWhiskey

2016/11/22

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; /** * A bit of empty space for bubbles to float in. * * @author Michael Kölling * @version 1.0 */ public class Space extends World { /** * Create Space. Make it black. */ public Space() { super(900, 600, 1); getBackground().setColor(Color.BLACK); getBackground().fill(); } private void setup () {setup(); } something like that?
danpost danpost

2016/11/22

#
Calling a method from within itself is not something you should do without great care (as coded above, the calling of the method will continue indefinitely, causing the project to throw an exception); anyway, Super_Hippo said to call the method from the constructor -- not from the method itself.
DocWhiskey DocWhiskey

2016/11/22

#
danpost wrote...
Calling a method from within itself is not something you should do without great care (as coded above, the calling of the method will continue indefinitely, causing the project to throw an exception); anyway, Super_Hippo said to call the method from the constructor -- not from the method itself.
Didn't realize i added setup() there actually thats my bad, i figured it out for the most part though thanks for the help guys
You need to login to post a reply.