Question: You must construct an algorithm that determines the size of the largest pile of leaves on the map that utilizes recursion. Your algorithm must return

You must construct an algorithm that determines the size of the largest pile of leaves on the map that utilizes recursion. Your algorithm must return the correct leaf pile size and must be able to work with different sized arrays. Rows and columns may not be the same, so you should not assume that they are. (If your algorithm is well constructed it should work on jagged arrays, although, I wont be testing for this.)

FOR YOUR HELP,you are provided with a main method (LeafPile.java) and the Ground enum (Ground.java).

LeafPile.Java code:

public class LeafPile { public static void main(String[] args) { Ground map[][] = new Ground[5][10]; generateRandomGround(map); printMap(map); System.out.println(largestLeafPile(map)); }

/***************** STUDENT CODE HERE *******************/

private static int largestLeafPile(Ground map[][]) { return 0; }

/**************** END STUDENT CODE **********************/

/************ Utility Methods *************/

private static void printMap(Ground map[][]) { for (int r = 0; r < map.length; r++) { for (int c = 0; c < map[r].length; c++) { if (map[r][c] == Ground.GRASS) { System.out.print(". "); } if (map[r][c] == Ground.LEAF) { System.out.print("~ "); } } System.out.println(); } }

private static void generateRandomGround(Ground map[][]) { int randGround; for (int r = 0; r < map.length; r++) { for (int c = 0; c < map[r].length; c++) { randGround = (int) (Math.random() * 2); map[r][c] = randGround == 0 ? Ground.GRASS : Ground.LEAF; } } }

/****************************************/ }

Ground.java code:

public enum Ground { GRASS('-'), LEAF('~'); private char symbol; private Ground(char value) { symbol = value; } public String toString() { return "" + symbol; } }

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!