For this activity you will use java.util.Stack to implement a stack that is used to determine whether a word is a palindrome. A palindrome is a word that is spelled the same from beginning to end and from end to beginning such as racecar.
Generate the following as output to the console:
The selected word prior to engaging the algorithm,
Individual stack pushes,
Stack contents upon pushing all letters of the word onto the stack,
Individual stack pops
String contents as you build the reverse of the word using stack pops,
The final string of the reverse of the word when finished popping the stack.
A message indicating whether the initial word and the reverse of the word formulate a palindrome or not.
Include appropriate package import declarations as needed.
Observe proper commenting/documentation techniques. Include clearly written comments/documentation to explain the purpose of major blocks of code. As needed/appropriate, include additional levels of comments/documentation detail to help you understand your code and logic as well as to help your reader understand the same.
Observe proper naming conventions for classes, attributes, methods, etc.
Other:
Process the words as strings.
Use the length() method to determine the string's length.
You can use a for loop to traverse strings one character at a time.
Use the substring(i, i) method to select each letter in the word to push onto the stack. Note that this method variant needs to use i+1 as the second parameter for this to work correctly.
Use the compareTo() method to determine whether the initial word and the reverse of the word are equal to each other. Note that this method returns a positive number if the first string is > the second string, a negative number if the first string is less than the second string, and zero if the two strings are equal. second string, and zero if the two strings are equal.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.