Question: Please help me with this Java method. Here is the findSum method. * * * * - * * - /** * Method calls helper
Please help me with this Java method. Here is the findSum method.


*
*
*
* - *
* - /** * Method calls helper to find contiguous values * adding to a specified number in an array *
* Note: Displays success or failed results *
* Rules of the searching process: * - The search starts in the upper left corner, * reporting each valid location found. * The solution must start from a location in the top row * and end in a location in the bottom row * - The method must search to a current location's right, * then below it, and then to its left, exactly in that order The method must report what it finds, * either as a successful candidate value * or a failed candidate value (and why it failed) The method must use recursive backtracking, * it must backtrack the recursion upon any failure, * but it must continue forward recursion upon any success * until the solution is found *
The method must be able to handle the condition * that the value in the upper left corner does not support the solution * * @param sumRequest integer value indicating desired sum * @return boolean indication of success public boolean findSum( int sumRequest ) { int startingXIndex = 0, startingYIndex = 0; int startingTotal = 0, startingRecLevel = 0; iteration Count = 0; System.out.println("Search Start:" ); if( findSumHelper( sumRequest, startingTotal, startingxIndex, startingIndex, startingRecLevel ) ) { System.out.println(" Search End: Successful Set: " + locationset.toString() ); System.out.println( "Iteration Count: " + iterationCount); return true; } System.out.println(" Search End: Solution Not Found" ); System.out.println( "Iteration Count: " + iterationCount); return false; } findSum Helper private boolean findSumHelper(int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel) Helper method to find requested sum in an array Note: Uses displayStatus method for all output (no other printing from this method); displayStatus provides appropriately indented current test location Parameters: sumRequest - integer value indicating desired sum runningTotal - integer current sum of search process xIndex integer current x position of search process yIndex integer current y position of search process recLevel integer current level of recursion, used to set display indent Returns: boolean indication of success *
*
*
* - *
* - /** * Method calls helper to find contiguous values * adding to a specified number in an array *
* Note: Displays success or failed results *
* Rules of the searching process: * - The search starts in the upper left corner, * reporting each valid location found. * The solution must start from a location in the top row * and end in a location in the bottom row * - The method must search to a current location's right, * then below it, and then to its left, exactly in that order The method must report what it finds, * either as a successful candidate value * or a failed candidate value (and why it failed) The method must use recursive backtracking, * it must backtrack the recursion upon any failure, * but it must continue forward recursion upon any success * until the solution is found *
The method must be able to handle the condition * that the value in the upper left corner does not support the solution * * @param sumRequest integer value indicating desired sum * @return boolean indication of success public boolean findSum( int sumRequest ) { int startingXIndex = 0, startingYIndex = 0; int startingTotal = 0, startingRecLevel = 0; iteration Count = 0; System.out.println("Search Start:" ); if( findSumHelper( sumRequest, startingTotal, startingxIndex, startingIndex, startingRecLevel ) ) { System.out.println(" Search End: Successful Set: " + locationset.toString() ); System.out.println( "Iteration Count: " + iterationCount); return true; } System.out.println(" Search End: Solution Not Found" ); System.out.println( "Iteration Count: " + iterationCount); return false; } findSum Helper private boolean findSumHelper(int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel) Helper method to find requested sum in an array Note: Uses displayStatus method for all output (no other printing from this method); displayStatus provides appropriately indented current test location Parameters: sumRequest - integer value indicating desired sum runningTotal - integer current sum of search process xIndex integer current x position of search process yIndex integer current y position of search process recLevel integer current level of recursion, used to set display indent Returns: boolean indication of success
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
