Other 2004 FR Questions | FR other years | Be Prepared Home |
// postcondition: returns true if this Robot has a wall immediately in // front of it, so that it cannot move forward; // otherwise, returns false public boolean forwardMoveBlocked() { return (facingRight && pos == hall.length - 1) || (!facingRight && pos == 0); 1 }Notes:
Part (b) // postcondition: one move has been made according to the // specifications above and the state of this // Robot has been updated private void move() { if (hall[pos] > 0) hall[pos]--; if (hall[pos] == 0) { if (forwardMoveBlocked()) facingRight = !facingRight; else if (facingRight) pos++; else pos--; } } Part (c) // postcondition: no more items remain in the hallway; // returns the number of moves made public int clearHall() { int count = 0; while (!hallIsClear()) { move(); count++; } return count; } |
Copyright © 2004 by Skylight Publishing
support@skylit.com