Class Diagram Assignment 11 will be the construction of a pr

Class Diagram:

Assignment #11 will be the construction of a program that takes an input string, and check each string separated by \'#\' if it is a palindrome or not. A string is a palindrome if it reads the same backward or forward, for example, \"kayak\" or \"level\".

Your program needs to read an input string that contains substrings separated by \'#\', for instance, \"kayak#level#sea\"
The method check() in the PalindromeChecker class needs to check if each of substrings in such input string is a palindrome using Stack and Queue. (Note that since there is no Queue class in the java library, you will need to use LinkedList class that implements Queue interface.)

Instruction:

Assignment11 class

This class displays a menu for the palindrome checking. If a user enters \"E\", then it asks to enter a string containing some substrings to check if they are palindromes. You can assume that such input string will contain at least one non-empty string with at least one character. This class is given by the instructor.

PalindromeChecker class

The PalindromeChecker class contains a constructor to set up an initial configuration.

You need to complete the following method.
Please see the PalindromeChecker.java for more details.

public void check()

You need to write the check method that reads every character of the input string until the end of the string or it encounters the character \'#\', and store every character into the stack, charStack, and into the queue, charQueue. Then it should remove every character from charStack and charQueue to see if the two characters are same.
If all characters are same, then it is a palindrome.
As an example, if the substring is \"kayak\", then the following output should be shown:
The input [k, a, y, a, k] is a palindrome

It should make use of toString( ) method of the Queue (LinkedList class).

If they are not same, then the substring is not palindrome, and it should print out the message:
The characters \'a\' and \'b\' do not match\ \

where \'a\' in this case is the character removed from the queue, and \'b\' is the character popped from the stack. Note that \'a\' and \'b\' are just examples, so it should display the first set of two characters that are different.

The following is an example, if the input substring is \"sea\", then the output should be:

The input [s, e, a] is not a palindrome
The characters \'s\' and \'a\' do not match


Please see the PalindromeChecker.java file for more details.

Requirements:

You need to implement this method using an object of the Stack class and LinkedList class (as a Queue) in java.util package.

Solution

Output:

-----------

Enter a string: kayak#level#sea
The input [k, a, y, a, k] is a palindrome
The input [l, e, v, e, l] is a palindrome
The characters a and s do not match

Process finished with exit code 0

Class Diagram: Assignment #11 will be the construction of a program that takes an input string, and check each string separated by \'#\' if it is a palindrome o
Class Diagram: Assignment #11 will be the construction of a program that takes an input string, and check each string separated by \'#\' if it is a palindrome o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site