Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the Robot class, the number of items on each tile in the hall is stored in the corresponding entry in the array hall. The
In the Robot class, the number of items on each tile in the hall is stored in the corresponding entry in the array hall. The current position is stored in the instance variable pos. The boolean instance variable facingRight is true if the Robot is facing to the right and is false otherwise.
a Write the Robot method forwardMoveBlocked. Method forwardMoveBlocked returns true if the robot has a wall immediately in front of it so that it cannot move forward. Otherwise, forwardMoveBlocked returns false.
Complete method forwardMoveBlocked below.
postcondition: returns true if this Robot has a wall immediately in
front of it so that it cannot move forward;
II
otherwise, returns false
private boolean forwardMoveBlocked
b Write the Robot method move. Method move has the robot carry out one move as specified at the beginning of the question. The specification for a move is repeated here for your convenience.
If there are any items on the current tile, then one item is removed.
If there are more items on the current tile, then the robot remains on the current tile facing the same direction.
If there are no more items on the current tile
a if the robot can move forward, it advances to the next tile in the direction that it is facing
b otherwise, if the robot cannot move forward, it reverses direction and does not change position.
In writing move, you may use any of the other methods in the Robot class. Assume these methods work as specified, regardless of what you wrote in part a Solutions that reimplement the functionality provided by these methods, rather than invoking these methods, will not receive full credit.
Complete method move below.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started