Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer following questions based on code below: 8. Why can we use a for-loop going down the mountain when we needed a while-loop going up?

Answer following questions based on code below:

8. Why can we use a for-loop going down the mountain when we needed a while-loop going up? Because we know how many times the loop needs to iterate to go back down but not up

9. How are we able to find base camp?

10. Which specific method call(s) result in different behaviors, depending on the object?

11. Does the steepness of the mountain change our code to go up and down? Why or why not?

12. How can different types of objects make use of a single, common code?

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago