Question: in JAVA Soil scientists characterize and classify soils into different groups. Each group of soil has differing ability to hold water depending on the particles

in JAVA
Soil scientists characterize and classify soils into different groups. Each group of soil has
differing ability to hold water depending on the particles inside. For the sake of simplicity, you
are given the internal structure of soil as n-by-n grid of cells. Each cell is either 1 or 0.
1 means, the cell allows water to drain.
0 means that cell will hold the water.
You need to create the required classes and methods to enable the following client application
to read data from a specified file and determine if water can drain from it. Please ensure that
your code works correctly with the provided sample code, as it will be tested using a file similar
to the one below.
public class Client {
public static void main(String[] args) throws Exception {
Soil soil = new Soil("sample1.txt");
if (soil.doesDrain()){
System.out.println("Allows water to drain");
} else {
System.out.println("Doesn't allow water to drain");
}
}
}
You are asked to implement and use the Weighted Quick Union with Path Compression union-
find algorithm to solve whether a soil example allows water to drain. You are not allowed to use
union-find implementations provided in alg4.jar.
Sample Input File-1:
10101
11010
01101
10101
10111
Expected Output:
Allows water to drain
Sample Input File-2:
10011
01110
10001
10001
11011
Expected Output:
Dont allow water to drain
Sample Input File-3:
1001111000
0111000110
1001100100
1000111000
1101111000
1011011110
0000110000
1011111000
0101101010
1101011000
Expected Output:
Allows water to drain

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!