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

2012/4/1

H

poila. poila.

2012/4/1

#
public static int FlysEaten = 0; // This is a constructor public void lookForFly() { if ( canSee(Fly.class) ) { eat(Fly.class); FlysEaten++; // This is a variable which } }
danpost danpost

2012/4/1

#
// THIS IS A CLASS VARIABLE
public static int FlysEaten = 0;
    // This is a constructor
// THIS IS NOT A CONSTRUCTOR
// THIS IS A METHOD DECLARATION
    public void lookForFly()
    {
        if ( canSee(Fly.class) )
        {
            eat(Fly.class);
            FlysEaten++;
            // This is a variable which
// IS THERE A QUESTION HERE?
        }
    }
poila. poila.

2012/4/2

#
danpost wrote...
// THIS IS A CLASS VARIABLE
public static int FlysEaten = 0;
    // This is a constructor
// THIS IS NOT A CONSTRUCTOR
// THIS IS A METHOD DECLARATION
    public void lookForFly()
    {
        if ( canSee(Fly.class) )
        {
            eat(Fly.class);
            FlysEaten++;
            // This is a variable which
// IS THERE A QUESTION HERE?
        }
    }
Hi danpost, I'm sorry i accidentally pressed enter without writing my question. My question was supposed to be What does this piece of code do, which you have said. But i'm still not sure what this bit mean: public void lookForFly() { if ( canSee(Fly.class) ) { eat(Fly.class); FlysEaten++; Thank you so much.
Michionlion Michionlion

2012/4/2

#
it is pretty self explanatory... public void lookForFly() { declares a method, and in the method... if (canSee(Fly.class)) { tests if the method canSee() returns true when you pass in Class Fly.class. if it does return true... eat(Fly.class) it calls the method eat(), passing in Fly.class, then... increments the FlysEaten variable by 1. In this example, you would need the methods canSee(Class) and eat(Class), neither of which are included in Greenfoot.
poila. poila.

2012/4/2

#
Michionlion wrote...
it is pretty self explanatory... public void lookForFly() { declares a method, and in the method... if (canSee(Fly.class)) { tests if the method canSee() returns true when you pass in Class Fly.class. if it does return true... eat(Fly.class) it calls the method eat(), passing in Fly.class, then... increments the FlysEaten variable by 1. In this example, you would need the methods canSee(Class) and eat(Class), neither of which are included in Greenfoot.
Thank you very much I know how it works now.
You need to login to post a reply.