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

2012/9/4

Using your introduction to Greenfoot book...compilation error occurs

MarkStPauls MarkStPauls

2012/9/4

#
Hi, Started teaching Java in Greenfoot and wanted to do the simple adaption to modern crab where you type: move(); I save the change and do a compile and an error comes up "method move in class greenfoot.Actor cannot be applied to given types; required:int; found:no arguments; reason:actual and formal argument list doffer in length" I assume there is something wrong with my install, or I am missing something elementary. move as far as I can see takes no arguments nor does it return any variable??? Does anyone have a solution?
MatheMagician MatheMagician

2012/9/4

#
move() does take an argument. You need to say something like move(5);.
nccb nccb

2012/9/5

#
There's two different crab projects. The modern crab is the updated one, adjusted to the latest Greenfoot API. The book uses a slightly older project, called little-crab (available in the book scenarios) where move is a method in the Animal class. If you want to follow the book, I'd use the book scenario (little-crab).
Gevater_Tod4711 Gevater_Tod4711

2012/9/5

#
public void move(int length) {
        double angle = Math.toRadians( getRotation() );
        int x = (int) Math.round(getX() + Math.cos(angle) * length);
        int y = (int) Math.round(getY() + Math.sin(angle) * length);
        setLocation(x, y);
    }
This is the move method from Crab. If you've got this method you easily can change it so that it works just like you want.
You need to login to post a reply.