Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me with this task and filling the code. Here is the code blank need to fill in: public class NodeStacking { // use
Please help me with this task and filling the code.
Here is the code blank need to fill in:
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 } }
Thanks for helping me!
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 1 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 programStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started