// PalindromeChecker.java public class PalindromeChecker { private String testString; // user entered string // constructor public PalindromeChecker() { testString = ""; } // end constructor // set testString public void settestString( String str ) { testString = str; } // end method settestString // get testString public String gettestString() { return testString; } // end method gettestString public String parseString() { String str = gettestString(); String newStr = ""; // string after all extraneous characters removed int length; // length of string char tempChar = ' '; // individual characters of the string for ( int i = 0; i <= str.length() - 1; i++ ) { tempChar = str.charAt( i ); if ( Character.isLetterOrDigit( tempChar ) ) // append letter or digit to newStr newStr += tempChar; } // end for return newStr; } // end method inputString // recursive method public boolean testPalindrome( String string ) { String str = string; String newStr; // ignores case of character in string e.g. a = A Character begChar = Character.toLowerCase( str.charAt( 0 ) ); Character endChar = Character.toLowerCase( str.charAt( str.length() - 1 ) ); // base case: length of string <= 1 if ( str.length() <= 1 ) { return true; } else if ( begChar.equals( endChar ) ) { if( str.length() == 2 ) return true; else { newStr = str.substring( 1, str.length() - 1 ); // shorten the string return testPalindrome( newStr ); // recursive call with shortened string } } // end if else { return false; // if 1st and last characters are different } } // end method testPalindrome } // end class