Question: // Task 1: public class ArraySum { /** * Implement a recursive method that takes an integer array, two indices as arguements * calulate the

 // Task 1: public class ArraySum { /** * Implement a

recursive method that takes an integer array, two indices as arguements *

// Task 1:

public class ArraySum { /** * Implement a recursive method that takes an integer array, two indices as arguements * calulate the sum from start to end of the array, and return the result. */ public static int arrSum(int[] arr, int start, int end) { // Filling your code here

// End of your code } }

// Task 2:

public class NodeStacking { // use this weight for calculating public static int weight = 128;

/** * Implement a recursive method that takes row index and column index of a node. * calculate the weight it supports. */ public static double weightSupporting(int row, int col) { // Filling your code here

// End of your code } }

Lab 5 This lab is to be completed individually This lab is for you to understand recursion. Please find two files ArraySum.java, NodeStacking.java and fill the method body. What to do? Task 1 Design and implement a recursive method for calculating the sum of an integer 1D-array with given start and end index. If the input index is invalid, please return O instead. For example, Input: (1,2,3,4,5,6), 2,5 Output: 18 Input: (1,2,3,4,5,6), -1,8 Output: 0 Task 2 Suppose there's a structure as follows. Each row of nodes is stacked together to form a pyramid. Each node weighs 128 pounds, and splits its weight evenly on the two nodes below it in the pyramid. For example, node A splits its weight across node B and node C. Node F splits its weight, plus the accumulated weight of the nodes it is supporting, onto node I and node J. Suppose this structure has infinite rows. The goal is to design and implement a recursive method that calculates how much weight a given node is supporting by specifying its row index and column index. Both indices start from 0, and each row has exact row index + 1 nodes. i.e. A is in row 0, column 0. F is in row 2, column 2. Your method should return -1 if the input indices are invalid. For example, Input 0, 0 which represents A, the output should be 0 Input 0, 1, which is an invalid index. The output should be -1 Input 1, 1, which is C. The supported weight should be the half of A's weight and the weight it's carrying. 1/2* (128 + 0) = 64. Thus, output should be 64. Please put your code between /* #. Filling your code here */ and /* #. End of code */. Follow the instructions in comments carefully. Do not change the code or structure outside the blocks. Make your own test cases to test the program. Lab 5 This lab is to be completed individually This lab is for you to understand recursion. Please find two files ArraySum.java, NodeStacking.java and fill the method body. What to do? Task 1 Design and implement a recursive method for calculating the sum of an integer 1D-array with given start and end index. If the input index is invalid, please return O instead. For example, Input: (1,2,3,4,5,6), 2,5 Output: 18 Input: (1,2,3,4,5,6), -1,8 Output: 0 Task 2 Suppose there's a structure as follows. Each row of nodes is stacked together to form a pyramid. Each node weighs 128 pounds, and splits its weight evenly on the two nodes below it in the pyramid. For example, node A splits its weight across node B and node C. Node F splits its weight, plus the accumulated weight of the nodes it is supporting, onto node I and node J. Suppose this structure has infinite rows. The goal is to design and implement a recursive method that calculates how much weight a given node is supporting by specifying its row index and column index. Both indices start from 0, and each row has exact row index + 1 nodes. i.e. A is in row 0, column 0. F is in row 2, column 2. Your method should return -1 if the input indices are invalid. For example, Input 0, 0 which represents A, the output should be 0 Input 0, 1, which is an invalid index. The output should be -1 Input 1, 1, which is C. The supported weight should be the half of A's weight and the weight it's carrying. 1/2* (128 + 0) = 64. Thus, output should be 64. Please put your code between /* #. Filling your code here */ and /* #. End of code */. Follow the instructions in comments carefully. Do not change the code or structure outside the blocks. Make your own test cases to test the program

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!