Question: Answer following questions based on code below: Explain the purpose of the first arg.putBeeper() and last arg.pickBeeper() commands of explore. 5. In explore_west, what is
Answer following questions based on code below:
Explain the purpose of the first arg.putBeeper() and last arg.pickBeeper() commands of explore.
5. In explore_west, what is the variable n actually counting?
6. How does the Climber know that it has reached the summit?
7. If the treasure isnt on the east summit, how do we know not to try to pick it up? If loop to pick beeper if it is there only
public class Mountain { public static void explore(Climber arg) { arg.putBeeper(); arg.turnLeft(); explore_west(arg); if(!arg.hasBeepers()) { explore_east(arg); } arg.pickBeeper(); } private static void explore_west(Climber arg) { int n = 0; while(arg.frontIsClear()) { arg.move(); } while(!arg.frontIsClear()) { arg.climbUpLeft(); n = n + 1; } if(arg.nextToABeeper()) { arg.pickBeeper(); } arg.turnAround(); for(int k = 1; k <= n; k++) { arg.climbDownRight(); } while(!arg.nextToABeeper()) { arg.move(); } } private static void explore_east(Climber arg) { int n = 0; while(arg.frontIsClear()) { arg.move(); } while(!arg.frontIsClear()) { arg.climbUpRight(); n = n + 1; } if(arg.nextToABeeper()) { arg.pickBeeper(); } arg.turnAround(); for(int k = 1; k <= n; k++) { arg.climbDownLeft(); } while(!arg.nextToABeeper()) { arg.move(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
