A word is said to be a palindrome if it is spelt the same forwards as backwards. For example, 'eye' and 'racecar' are palindromes, but 'hello' and 'book' are not.
Write a class Palindromes that uses a stack and/or queue to check whether a given word is a palindrome (case-sensitive). Use the structure shown below:
public class Palindromes {
/**
* Returns true if word is a palindrome, false if not
*/
public static boolean isPalindrome(String word) throws EmptyStackException, EmptyQueueException;
}
To test your code, Add a JUnit test class PalindromesTest, and include at least the following test cases:
testEmptyString(), which checks that the empty string is a palindrome
testBasicPalindromes(), which ensures that 'eye' and 'racecar' are palindromes
testBasicNonPalindromes(), which ensures that 'hello' and 'book' are not palindromes
testCase(), which checks that 'EyE' is a palindrome but 'Eye' is not
Comments
Leave a comment