Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a two-dimensional array of values that give the height of a terrai

ID: 658294 • Letter: Y

Question

You are given a two-dimensional array of values that give the height of a terrain at different points in a square.

Write a constructor

and a method

Then write a program that prints out a flood map, showing which of the points in the terrain would be flooded if the water level was the given value. In the flood map, print a * for each flooded point and a space for each point that is not flooded.

Here is a sample map

Then write a program that reads one hundred terrain height values and shows how the terrain gets flooded when the water level increases in ten steps from the lowest point in the terrain to the highest

Explanation / Answer

//Header file section
import java.util.Random;
import java.lang.*;
//main class
public class Terrain
{
public static void main(String[] args)
    {
        final int num = 10;
           Random ran = new Random();
           int waterLevel=ran.nextInt(10);
         
           double[][] heights = new double[num][num];
           for (int row=0; row<num; row++)       
                   for (int col=0; col<num; col++)
                           heights[row][col] = ran.nextInt(10);          
         
           System.out.print("A flood map for a water level of "+waterLevel+": ");
           Terrain map = new Terrain(heights);
           map.printFloodMap(100);
    }
//declare variables
    double[][] heights = new double[20][20];
    int i, j;
    //Constructor:two-dimensional array of values that give
    //the height of a terrain at different points in a square.
    public Terrain(double[][] heights)
    {
   

        this.heights = heights;
    }

    //Method definition of printFloodMap
    public void printFloodMap(double waterLevel)
    {
        if(waterLevel>heights[i][j])
        {

            String[][] map = null;
            map[i][j] = "*";
            System.out.print(map[i][j]);
        }
        else
        {
            String[][] map = null;
            map[i][j] = " ";
            System.out.print(map[i][j]);
        }

    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote