0

So I have to use the becker.robots package to move forward and pick up a certain amount of flashers and then turn around and place them. However, I am not sure how to invoke the robot.move() method. Everytime I try to make it move forward I get a compiler error saying :

Error: method move in class becker.robots.Robot cannot be applied to given types; required: no arguments found: int reason: actual and formal argument lists differ in length

Could someone please help me :)

Compass
  • 5,867
  • 4
  • 30
  • 42

2 Answers2

0
  • required: no arguments
  • found: int

you're writing robot.move(5) or something else that resolves into a number, you're supposed to write robot.move(). Use for example a loop if you want to move 5 times.

zapl
  • 63,179
  • 10
  • 123
  • 154
0

Moving a robot in Karel/Becker can only move a single step at a time. By design, of course.

From the documentation.

If you wish to move 6 spaces forward, you will need to do a for loop:

for(int i = 0; i < 6; i++) {
    robot.move();
}

Or call robot.move() 6 times:

    robot.move();
    robot.move();
    robot.move();
    robot.move();
    robot.move();
    robot.move();

Alternatively, can create a method to move it multiple times.

void customMove(int move) {
    for(int i = 0; i < move; i++) {
        robot.move();
    }
}

Then a call of customMove(6); will move Karel forwards 6 times.

Obviously, to avoid breaking Karel, you should check if it's clear before moving, but this is a conceptual design for movement.

Compass
  • 5,867
  • 4
  • 30
  • 42