Question

In: Computer Science

Write a recursive method to determine if a String is a palindrome. The program should contain...

Write a recursive method to determine if a String is a palindrome.

The program should contain a String array that you can load several test cases to test your palindrome testing method.

The program should load your String Array with the test data containing the possible palindromes from a text file.

The program should test you application with a text file contained in your project folder

After testing your program with your test cases in the text file, you program should allow the user to test your program independently and interactively using Command Line Interface (CLI).

javadoc Requirement

There is also a javadoc requirement for the Java application projects developed in the course. All Java projects must also contain javadoc documentation with it when submitted. There is an option to create javadocs in Intellij. As long as you have your code commented properly, the javadoc will be automatically generated when you selected the option to generate it in Intellij. I uploaded a pdf document describing how to comment your code to generate your javadoc documentation correctly. There are also two hyperlinks leading to internet tutorials on creating javadoc documentation.

Submit Your Application, your Lab Report, and your text file. Your text file should be in your project folder. You must permit the user to enter their own palindrome after the test in run


Solutions

Expert Solution

Program Code Screenshot :

Sample Output :

Program Code to Copy

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

class Main{

    //Method to find whether a palindrome or not
    static boolean isPalindrome(String s){
        if(s.length()<=1){
            return true;
        }
        if(s.charAt(0)!=s.charAt(s.length()-1)){
            return false;
        }
        return isPalindrome(s.substring(1,s.length()-1));
    }

    public static void testIsPalindrome(String testFile) throws IOException {
        //Read the file for test cases
        BufferedReader br = new BufferedReader(new FileReader(testFile));
        String s;
        boolean pass = true;
        //Read all lines
        while((s=br.readLine())!=null){
            String data[] = s.split(",");
            String in = data[0];
            boolean result = data[1].equalsIgnoreCase("true");
            boolean b =isPalindrome(in);
            //Check if output matches the expected
            if(b!=result){
                System.out.println(s+" Expected : "+result+", Actual : "+b);
                pass = false;
            }
        }
        if(pass){
            System.out.println("All tests Passed");
        }
        else{
            System.out.println("There are failed test cases");
        }
    }

    public static void main(String[] args) throws IOException {
        testIsPalindrome("D:/test.txt");
        Scanner obj = new Scanner(System.in);
        System.out.println("Enter the String");
        String s = obj.nextLine();
        if(isPalindrome(s)) {
            System.out.println(s+" is palindrome");
        }
        else{
            System.out.println(s+" is not a palindrome");
        }
    }
}

Related Solutions

Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Write a short recursive C++ function that determines if a string s is a palindrome, that...
Write a short recursive C++ function that determines if a string s is a palindrome, that is, it is equal to its reverse. For example,"racecar" and "gohangasalamiimalasagnahog" are palindromes. Please include the pseudo code so that I can understand better with simple English as much as possible.
​Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.
Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.(JAVA Code)
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
java Write a recursive program to reverse a positive integer. . Your method should take a...
java Write a recursive program to reverse a positive integer. . Your method should take a non negative integer as a parameter and return the reverse of the number as an integer. e.g. if you pass 12345, your method should return 54321.
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Need code in c#.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT