.1 TELUS 12:02 AM * 100%- Problem 4. (25 points) You are given a two-dimensional
ID: 3607667 • Letter: #
Question
.1 TELUS 12:02 AM * 100%- Problem 4. (25 points) You are given a two-dimensional array of values that specify the height of a terrain at different points in a square. Write a Java program with the following tasks: array. You can assume that the heights are integer values Constructor of the class A method to find the lowest point of the terrain. A method to find the highest point of the terrain. A method to print out a flood map, showing which of the points in the terrain would be flooded if the water level was a given value. In the flood map, print a *for each flooded point and a -for each point that is not flooded. Here is a sample map for a 5 by 5 square: Test your implemented class using a4 by 4 squared terrain Note: Your main class should work for squared terrains with any sizeExplanation / Answer
import java.io.*;
import java.util.*;
public class DemoTerrain{
public static void read(int a[][], int n){
Scanner sc = new Scanner(System.in);
for (int i = 0; i<n; i++){
for (int j = 0; j<n; j++){
a[i][j] = sc.nextInt();
}
}
}
public static void highest(int a[][], int n){
int max = a[0][0];
int i1 = 0;
int j1 = 0;
for (int i = 0; i<n; i++){
for (int j = 0; j<n; j++){
if (max < a[i][j]){
max = a[i][j];
i1 = i;
j1 = j;
}
}
}
System.out.println("Highest point " + max + " at " + i1 + " " + j1);
}
public static void lowest(int a[][], int n){
int min = a[0][0];
int i1 = 0;
int j1 = 0;
for (int i = 0; i<n; i++){
for (int j = 0; j<n; j++){
if (min > a[i][j]){
min = a[i][j];
i1 = i;
j1 = j;
}
}
}
System.out.println("Lowest point " + min + " at " + i1 + " " + j1);
}
public static void floodmap(int a[][], int n,int d){
int min = a[0][0];
for (int i = 0; i<n; i++){
for (int j = 0; j<n; j++){
if (a[i][j] <= d)
System.out.print("* ");
else
System.out.print("_ ");
}
System.out.println();
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter size of terrain :");
int n = sc.nextInt();
int [][] a = new int[n][n];
System.out.println("Enter values rowwise :");
read(a,n);
lowest(a,n);
highest(a,n);
System.out.println("Enter water level :");
int d = sc.nextInt();
floodmap(a,n,d);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.