Menu

(Solved) : Palindrome Word Phrase Number Reads Forwards Backwards Example Madam Borrow Rob 1991 Consi Q29097056 . . .

A palindrome is a word, phrase or number thatreads the same forwards or backwards. For example,

madam
borrow or rob?
1991

… are all considered palindromes. Note that punctuation andspaces are generally ignored when judging whether a phrase ispalindromic.

A palindromic date is one that reads the same forward orbackward, without regard to any month/day/year separators. January2, 2010 is a palindromic year when expressed in a MMDDYYYY format:01022010; June 1, 2016 is palindromic when using a MDYY format:6116.

For programming project #4 develop a Java program with threedifferent methods that each determine whether a string entered bythe user is a palindrome, per the following requirements:

Develop a command line interface (CLI) that allows the user toenter a word, phrase or number and report back to the user whetherthe input is a palindrome.

After reporting the results for a given input, allow the user toenter another string to be tested. Provide some mechanism for theuser to end the program; for example, entering the wordquit.

Before checking the user’s input, filter out all spaces andpunctuation.

Each user entry is to be checked by each of three palindromecheckers:

an iterative algorithm;

a recursive algorithm; and

an algorithm that makes meaningful use of both a stack and aqueue in determining whether the input is palindromic

Report out the result for each of the three checkers, andinclude the how long it took to determine the result. UsenanoTime() or some other timing mechanism to measure the executiontime. Be sure your timing logic focuses on the palindrome testingalgorithm and does not include any time for input or output.

In addition to submitting all of your source code in a singleEclipse project, an overall description of the project and a simpletest plan are required elements of this assignment. The descriptionshall include a section that compares the iterative and recursivemethods in regards to time and space efficiency. For the test plan,simply list at least ten words or phrases to be used to test yourprogram, half of which are palindromes and half are not. A majorityof your test entries must be phrases (i.e., more than one word) andsome of them must include punctuation as well as spaces. Your listof test data is to be included in the description document.

Source code 80 points
Description    10 points
“Test plan” 10 points

I need the Test plan and descriptionhttps://gyazo.com/9d61569555d21409c38d647215bfd93a

Here is my code

import java.util.*;

class Main{

public static void main(String a[]){

System.out.println(“Palindrome Test”);

Scanner input = new Scanner(System.in);

String choice = “”;

while(choice.compareTo(“2”) != 0){

System.out.print(“nType ‘1’ for palindrome check Type ‘2’ toexit. “

+ “sn1.Palindrome checkern2.ExitnPlease enter yourchoice:”);

choice = input.nextLine();

if(choice.compareTo(“1”) == 0){

System.out.print(“nPlease enter string to be tested:”);

String inputString = input.nextLine();

inputString = inputString.replaceAll(“[^w]”,””);

System.out.print(“nTesting :” + inputString);

executePalindrome(inputString.toLowerCase());

}

}

}

static void executePalindrome(String inputString){

Palindrome p = new Palindrome();

Long start, end;

Boolean result;

LinkedList LL = new LinkedList();

for(int i=0;i<inputString.length();i++)

LL.add(inputString.charAt(i));

start = System.nanoTime();

result = p.iterative(inputString);

end = System.nanoTime();

System.out.println(“nIterative: ” + result + ” ,Time: ” + (end- start) + ” nanoseconds.”);

start = System.nanoTime();

result = p.recursive(inputString);

end = System.nanoTime();

System.out.println(“Recursive: ” + result + ” ,Time: ” + (end -start) + ” nanoseconds.”);

start = System.nanoTime();

result = p.algorithm(LL);

end = System.nanoTime();

System.out.println(“Algorithmic: ” + result + ” ,Time: ” + (end- start) + ” nanoseconds.”);

}

}

class Palindrome{

boolean iterative(String a){

for(int i=0;i<a.length() / 2;i++){

if(a.charAt(i) != a.charAt(a.length()-1 – i))

return false;

}

return true;

}

boolean recursive(String a){

if(a.charAt(0) == a.charAt(a.length() – 1)){

if(a.length() > 2)

return recursive(a.substring(1, a.length()-1));

else

return true;

}

return false;

}

boolean algorithm(Queue<Character> q){

int halfSize = q.size() / 2;

Stack<Character> stack = new Stack<Character>();

for(int i=0;i<halfSize;i++){

stack.push(q.remove());

}

if(q.size() != stack.size())

q.remove();

for(int i = 0;i<q.size();i++){

if(stack.pop() != q.remove())

return false;

}

return true;

}

}

Expert Answer


Answer to Palindrome Word Phrase Number Reads Forwards Backwards Example Madam Borrow Rob 1991 Consi Q29097056 . . .

OR