... I need a code for the findPath() method to Recursively find a path and Mark
ID: 3542285 • Letter: #
Question
...
I need a code for the findPath() method to Recursively find a path and Mark the direction to move in next with (N,E,S,W) and the end poit with "^"
here is my code with the empty findpath Method
import java.io.*;
import java.util.Scanner;
public class TerrainScanner
{
private double terrain[][];
char map[][] = new char[10][10];
/**
* @param in scanner to read from input file
* @param r row
* @param c column
* @param sum take sum of rows
*/
public void scanTerrain(String terrainMap)
throws IOException
{
Scanner in = new Scanner(new BufferedReader(new FileReader(terrainMap)));
for(int r = 0; r < 10; r++)
{
for(int c = 0; c < 10; c++)
{
int sum = 0;
for(int i = 0; i < 6; i++)
sum += in.nextInt();
in.nextLine();
terrain[r][c] = sum / 6.00;
}
}
}
/**
* @param in scanner to read from input file
* @param r row
* @param c column
*/
public char[][] generateMap(int threshold)
{
for(int r = 0; r < 10; r++)
{
for(int c = 0; c < 10; c++)
{
char mark;
if(terrain[r][c] > (double)threshold)
{
mark = 'X';
} else
{
mark = ' ';
int i = 0;
if(r + 1 < 10 && checkIfPassable(r + 1, c, threshold))
i++;
if(r - 1 >= 0 && checkIfPassable(r - 1, c, threshold))
i++;
if(c + 1 < 10 && checkIfPassable(r, c + 1, threshold))
i++;
if(c - 1 >= 0 && checkIfPassable(r, c - 1, threshold))
i++;
mark = (char)(i + 48);
}
map[r][c] = mark;
}
}
return map;
}
/**
* @return terrain at the current position within selected threshold
*/
public boolean checkIfPassable(int row, int col, int threshold)
{
return terrain[row][col] <= (double)threshold;
}
/**
* @return highest elevations
*/
public double getHighestElevation()
{
double max = terrain[0][0];
for(int r = 0; r<10; r++){
for (int c = 0; c<10; c++)
if(max < terrain[r][c]){
max = terrain[r][c];
}
}
return max;
}
/**
* @return lowest elevation
*/
public double getLowestElevation()
{
double min = terrain[0][0];
for(int r = 0; r<10; r++){
for (int c = 0; c<10; c++)
if(min > terrain[r][c]){
min = terrain[r][c];
}
}
return min;
}
/**
* @param terrain = 2D array to hold terrain averages
*/
public TerrainScanner()
{
terrain = new double[10][10];
}
public char[][] findPath(int startRow, int startCol, int destRow, int destCol,
int threshold){
}
}
Explanation / Answer
hhhhh
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.