Question: Please help me make a method called private boolean findSumHelper in java. Here is the rest of the class public class MatrixAnalysisClass : public class
Please help me make a method called private boolean findSumHelper in java. Here is the rest of the class public class MatrixAnalysisClass :










public class MatrixAnalysisClass { /** * constant definition for maximum input string */ private static final int MAX_INPUT_CHARS = 80; /** * constant definition of EoF marker */ private static final int EOF_MARKER = -1; /** * constant specification of number of spaces * for each recursive level indent */ private final int REC_LEVEL_INDENT = 3; /** * constant definition for COLON */ private static final char COLON = ':'; /** * constant definition for SPACE */ private static final char SPACE = ''; /** * constant definition for minus sign private static final char MINUS_SIGN = '-'; /** * constant control code for display method private static final int VALID_ITEM = 101; /** * constant control code for display method */ private static final int INVALID ITEM = 102; /** * constant control code for display method */ private static final int OVER_SUM = 103; /** * constant control code for display method */ private static final int OUT_OF_BOUNDS = 104; /** * constant control code for display method */ private static final int TEST_LOCATION = 105; */ */ * constant control code for display method */ private static final int NO_SOLUTION = 106; /** * FileReader object used for data upload */ private FileReader fileIn; /** * flag selects show operations */ private boolean verboseFlag; /** * specification of member row height */ private int arrayRowHeight; /** * specification of member row width */ private int arrayRowWidth; /** * counts number of recursive calls */ private int iterationCount; /** * two dimensional array for data storage */ private int[] [] dataArray; /** * SimpleGenericsetClass holds locations found during search */ private SimpleGenericSetClass * 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 be low 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, starting RecLevel = 0; iterationCount = 0; System.out.println("Search Start:" ); if( findSumHelper( sumRequest, startingTotal, startingxIndex, startingyIndex, startingRecLevel ) ) { System.out.println(" Search End: Successful Set: " + locationSet.toString() ); System.out.println( "Iteration Count: " + iteration Count); return true; } System.out.println(" Search End: Solution Not Found" ); System.out.println("Iteration Count: " + iterationCount); return false; } /** * 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 * @param sumRequest integer value indicating desired sum * @param runningTotal integer current sum of search process * @param xIndex integer current x position of search process * @param yIndex integer current y position of search process * @param recLevel integer current level of recursion, used to set display indent * @return boolean indication of success */ private boolean findSumHelper( int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel ) { // TO DO return false; //temp. stub return } @SuppressWarnings ( "unused" ) private boolean findSumHelper_NoDisplay( int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel ) { CelldataClass currentCelldata = new CelldataClass( 0, xIndex, yIndex); int currentValue = 0; iteration Count++; if(!isInBounds( xIndex, yIndex ) ) { return false; } currentValue = dataArray ( yIndex ][ xIndex ]; runningTotal += currentValue; currentCellData = new CellDataClass( currentValue, xIndex, yIndex ); if( locationSet.hasItem( currentCelldata ) ) { return false; } if( runningTotal > sumRequest ) { return false; } // successful location found location Cat addTtamurrantcalinata. locationSet.addItem( currentCellData ); if( runningTotal == sumRequest && yIndex == arrayRowHeight 1) { return true; } if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex + 1, yIndex, recLevel + 1 ) ) { return true; } else if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex, yIndex + 1, recLevel + 1 ) ) { return true; } else if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex - 1, yIndex, recLevel + 1 ) ) { return true; } else { LocationSet. removeLastItem(); } if( recLevel == 0 && xIndex = 0 && xLocTest = 0 && yLocTest * * * Displays for * 1) location not found, * 2) item already in set, * 3) item causes over sum condition (opSuccess code OVER_SUM), * 4) item has exhausted all child tests and does not support the solution * (opSuccess code INVALID_ITEM), * 5) item accepted (opSuccess code VALID_ITEM), shows current location * @param recLevel integer specification of current level * @param status String indication of success or failure * @param opSuccess integer code indicating success or different failures * @param current Celldataclass data at current level */ private void displayStatus(int recLevel, String status, CelldataClass current, int opSuccess) { int index, recLevel Indent = recLevel * REC_LEVEL_INDENT; if( verboseFlag) { for( index = 0; index = (int) ( SPACE ) ) { strBuffer += (char)( inCharInt); index++; } inCharInt = fileIn.read(); } 1/inCharInt = fileIn.read(); } catch( IOException ioe ) { System.out.println("INPUT ERROR: Failure to capture character" ); strBuffer = ""; } return strBuffer; } /** * gets an integer from the input string * @param maxLength maximum length of characters * input to capture the integer * @return integer captured from file */ nrivate int notAnIntl int mavl onath private int getAnInt( int maxlength ) { int inCharInt; int index = 0; String strBuffer = ""; int intValue; boolean negativeFlag = false; try { inchar Int = fileIn.read(); // clear space up to number while( index 0) { System.out.print(", ); } System.out.print( dataArray( rowIndex ][ colindex ] ); } II System.out.println(); } System.out.println(); } * * * * tests and reports if a character is found in a given string * @param testchar character to be tested against the string * @param testString string within which the character is tested * @return Boolean result of test */ private boolean charInString( char testChar, String testString) { int index; for( index = 0; index locationSet; /** * Default constructor */ public MatrixAnalysisClass() { dataArray = null; verboseFlag = false; arrayRowWidth = arrayRowHeight 0; LocationSet = new SimpleGenericSetClass * 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 be low 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, starting RecLevel = 0; iterationCount = 0; System.out.println("Search Start:" ); if( findSumHelper( sumRequest, startingTotal, startingxIndex, startingyIndex, startingRecLevel ) ) { System.out.println(" Search End: Successful Set: " + locationSet.toString() ); System.out.println( "Iteration Count: " + iteration Count); return true; } System.out.println(" Search End: Solution Not Found" ); System.out.println("Iteration Count: " + iterationCount); return false; } /** * 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 * @param sumRequest integer value indicating desired sum * @param runningTotal integer current sum of search process * @param xIndex integer current x position of search process * @param yIndex integer current y position of search process * @param recLevel integer current level of recursion, used to set display indent * @return boolean indication of success */ private boolean findSumHelper( int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel ) { // TO DO return false; //temp. stub return } @SuppressWarnings ( "unused" ) private boolean findSumHelper_NoDisplay( int sumRequest, int runningTotal, int xIndex, int yIndex, int recLevel ) { CelldataClass currentCelldata = new CelldataClass( 0, xIndex, yIndex); int currentValue = 0; iteration Count++; if(!isInBounds( xIndex, yIndex ) ) { return false; } currentValue = dataArray ( yIndex ][ xIndex ]; runningTotal += currentValue; currentCellData = new CellDataClass( currentValue, xIndex, yIndex ); if( locationSet.hasItem( currentCelldata ) ) { return false; } if( runningTotal > sumRequest ) { return false; } // successful location found location Cat addTtamurrantcalinata. locationSet.addItem( currentCellData ); if( runningTotal == sumRequest && yIndex == arrayRowHeight 1) { return true; } if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex + 1, yIndex, recLevel + 1 ) ) { return true; } else if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex, yIndex + 1, recLevel + 1 ) ) { return true; } else if( findSumHelper_NoDisplay( sumRequest, runningTotal, xIndex - 1, yIndex, recLevel + 1 ) ) { return true; } else { LocationSet. removeLastItem(); } if( recLevel == 0 && xIndex = 0 && xLocTest = 0 && yLocTest * * * Displays for * 1) location not found, * 2) item already in set, * 3) item causes over sum condition (opSuccess code OVER_SUM), * 4) item has exhausted all child tests and does not support the solution * (opSuccess code INVALID_ITEM), * 5) item accepted (opSuccess code VALID_ITEM), shows current location * @param recLevel integer specification of current level * @param status String indication of success or failure * @param opSuccess integer code indicating success or different failures * @param current Celldataclass data at current level */ private void displayStatus(int recLevel, String status, CelldataClass current, int opSuccess) { int index, recLevel Indent = recLevel * REC_LEVEL_INDENT; if( verboseFlag) { for( index = 0; index = (int) ( SPACE ) ) { strBuffer += (char)( inCharInt); index++; } inCharInt = fileIn.read(); } 1/inCharInt = fileIn.read(); } catch( IOException ioe ) { System.out.println("INPUT ERROR: Failure to capture character" ); strBuffer = ""; } return strBuffer; } /** * gets an integer from the input string * @param maxLength maximum length of characters * input to capture the integer * @return integer captured from file */ nrivate int notAnIntl int mavl onath private int getAnInt( int maxlength ) { int inCharInt; int index = 0; String strBuffer = ""; int intValue; boolean negativeFlag = false; try { inchar Int = fileIn.read(); // clear space up to number while( index 0) { System.out.print(", ); } System.out.print( dataArray( rowIndex ][ colindex ] ); } II System.out.println(); } System.out.println(); } * * * * tests and reports if a character is found in a given string * @param testchar character to be tested against the string * @param testString string within which the character is tested * @return Boolean result of test */ private boolean charInString( char testChar, String testString) { int index; for( index = 0; index
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
