Sunday, 6 February 2011

Grid World Page 12

1. What is the role of the instance variable sideLength?
sideLength calculates how many steps BoxBug travels before it turns 90 degrees right.(clockwise) 
2. What is the role of the instance variable steps?  
Like the name of the variable indicates, it counts the amount of steps the BoxBug has done since last turn.Every turn, the variable resets, or goes back to 0 and counts until the next turn. 
3. Why is the turn() method called twice when steps becomes equal to sideLength?  
A single turn() method would turn it by 45 degrees.So twice calling it will make it do a 90 degree turn. 
4. Why can the move() method be called in the BoxBug class when there is no move() method in the BoxBug code?  
All the methods from the BoxBug class extend to the Bug class so the move() method should also be available in the Bug class.
5. After a BoxBug is constructed, will the size of its square pattern always be the same? Why or why not?
No the size of the square pattern will never change.There is not method to change the size of the square pattern so it will remain the same as default. 
6. Can the path a BoxBug travels ever change? Why or why not?  
Yes the path will always change. Even if the amount of steps is not sufficient, the bug will change its direction at every single corner or touching the boundary. 
7. When will the value of steps be zero?  
It changes to zero when it has reached the right amount of steps or it meets a corner of the grid.

No comments:

Post a Comment