Question
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.
- Starting from the given row, and column 0, color it red (already
- done in the Driver class).
- Write a loop that generates every possible column across the
- 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
- 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.
- Use a variable that keeps track of the 'current row' you're on,
- and update it each time you take a step forward - row may stay
- the same, or go up or down by 1 depending how you walk.
- UseMath.abs(...)to get the absolute value of the difference
- between two elevations.
- Continue finding the lowest neighboring cell and coloring it
- green as you go.
- Keep a running total of the total elevation change that would be
- '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
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started