Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The pickThingsToWall method, shown in Listing 5-4 and illustrated in Figure 5-6,

ID: 3867381 • Letter: T

Question

The pickThingsToWall method, shown in Listing 5-4 and illustrated in Figure 5-6, instructs a robot to move to a wall, picking one Thing from each intersection that has one. Describe the changes required to make the robot pick up an entire pile of things from those intersections that have them. Review your fellow programmers' posts and choose one that chose a different path than yours. Discuss why you think your method is better (or not) with a reply post.

listing 5-4:

/** Pick up one thing (if there is a thing) from each intersection between this robot and the
* nearest wall it is facing. */
public void pickThingsToWall()
{while(this.frontIsClear())
{this.move();
if(this.canPickThing())
{this.pickThing();
}
}

}

Explanation / Answer

Explanation: We need to change the if statement in listing 5-4 to while statement. So, while there are things left in a pile, the robot will keep picking, until the entire pile of things is picked up.

public void pickThingsToWall()
{while(this.frontIsClear())
{this.move();
while(this.canPickThing())
{this.pickThing();
}
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote