I have been given the task of writing a segment of code using the becker.robots package and I must create a method called pickUpThings for a class which has a parameter for the number of Things to be picked up ie

public void pickUpThings(int thingsToBePickedUp)

I have figured out that i must create a segment of code which lets me use a while loop (i think)

while(this.countThingsInBackpack() < thingsToBePickedUp)
{
    //...
}

Assumptions:

  1. There will be either 0 or 1 things on each intersection.
  2. Enough 'things' will be laid out in front of the robot.

Also, the robot travels on the same intersection i.e. heading east for the entire coded procedure.

有帮助吗?

解决方案

From the sounds of it your starting point is correct the logic should be along the lines of;

while (stuff in backpack is less than the stuff that needs to be picked up)
    if there is somthing on the intersection I am on then
        put it in backpack
    endif
    move forward
end while

As for how to put that in code would you be able to figure that out or would you like my to edit with something that would compile?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top