Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement thedrawLowestElevPath(Graphics, startRow)method. Note that this method does two things: 1) it draws the path, 2) it calculates and returns to the total elevation change

Implement thedrawLowestElevPath(Graphics, startRow)method. Note that this method does two things: 1) it draws the path, 2) it calculates and returns to the total elevation change on that path. The method should draw a line by drawing 1x1 filled rectangles in a different color on top of the existing drawing. The path should be drawn going West-to-East, starting from the given row using the greedy lowest-elevation-change technique described in earlier pages.

You will need to do the following things in some order.

  1. Starting from the given row, and column 0, color it red (already
  2. done in the Driver class).
  3. Write a loop that generates every possible column across the
  4. map from 1 to 480 (you start at column 0, but column 1 is the first column you need to make choice about where to step). For
  5. each column you will decide which row to take your next "step"

to - fwd, fwd-and-up, or fwd-and-down - using the greedy choice

strategy described.

  1. Use a variable that keeps track of the 'current row' you're on,
  2. and update it each time you take a step forward - row may stay
  3. the same, or go up or down by 1 depending how you walk.
  4. UseMath.abs(...)to get the absolute value of the difference
  5. between two elevations.
  6. Continue finding the lowest neighboring cell and coloring it
  7. green as you go.
  8. Keep a running total of the total elevation change that would be
  9. 'experienced' by a person walking this path. Since we consider an elevation change the absolute value (i.e. going 'uphill' 10 meters is the same amount of change as going 'downhill' 10 meters) this running total will be non-decreasing and will end up being a pretty large positive number
  10. When you're done you should see a line tracing the lowest elevation-change path from west to east. Here is the image you should see (path may vary slightly due to equivalent choices)

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Programming questions