Answered step by step
Verified Expert Solution
Question
1 Approved Answer
***Please use the provided files, the interface does not need to be edited*** ***Interface*** package asmt02Part03; /** * An interface for the ADT stack. *
***Please use the provided files, the interface does not need to be edited***
***Interface***
package asmt02Part03; /** * An interface for the ADT stack. * * **************************** PLEASE DO NOT CHANGE THIS FILE *********** * * @param T> */ public interface StackInterface{ /** Adds a new entry to the top of this stack. @param newEntry An object to be added to the stack. */ public void push(T newEntry); /** Removes and returns this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty before the operation. */ public T pop(); /** Retrieves this stack's top entry. @return The object at the top of the stack. @throws EmptyStackException if the stack is empty. */ public T peek(); /** Detects whether this stack is empty. @return True if the stack is empty. */ public boolean isEmpty(); /** Removes all entries from this stack. */ public void clear(); } // end StackInterface
***File 1***
package asmt02Part03; import java.util.Stack; /** * A class of stacks. */ public class OurStackimplements StackInterface { Stack theStack; public OurStack() { theStack = new Stack(); } // end default constructor public void push(T newEntry) { theStack.push(new newEntry); } // end push public T peek() { return theStack.peek(); } // end peek public T pop() { return theStack.pop(); } // end pop public boolean isEmpty() { return theStack.empty(); } // end isEmpty public void clear() { } // end clear } // end OurStack
***File 3***
package asmt02Part03; import java.util.Scanner; /** * * A class that determines whether or not a string is a palindrome; * that is, a string that's able to be spelled the same way from * left to right as it is right to left, ignoring punctuation, * spaces, and case. * */ public class PalindromeChecker { /** * * Tests whether a string is a palidrome, * ignoring punctuation, spaces, and case. * * @param aString A string. * @return * * */ public static boolean isPalindrome(String aString) { StringBuilder tempString = new StringBuilder(aString); // // // // // // // // // while (!done && (continuingIndex /** Tests whether a character is a punctuation mark, such as a period. * * @param aCharacter The character to be tested. * @return True if the character is a punctuation mark, or false if not. * */ public static boolean isPunctuation(char aCharacter) { // } // end isPunctuation public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // System.out.println("Done!"); } // end main } // end PalindromeChecker
A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward-assuming that you ignore spaces, punctuation (https://simple.wikipedia.org/wiki/Punctuation. Do not worry about ellipsis, n-dash, and m-dash.), and case. For example, Race car is a palindrome. So is A man, a plan, a canal: Panama. (More palindromes, http://www.palindromelist.net/) Write a Java program that uses a stack to test whether an input string is a palindrome. Sample output: Enter a string that you want to check (or enter ! to exit): Ah, Satan sees Natasha ! | Ah, Satan sees Natasha! Is a palindrome! Enter a string that you want to check (or enter to exit): Amy, must 1 jujitsu my ma ? Amy, must I jujitsu my ma? IS a palindrome! Enter a string that you want to check (or enter to exit): A man, a plan, a canal: Panama. A man, a plan, a canal: Panama. IS a palindrome! Enter a string that you want to check (or enter to exit): Are Mac 'n' 0liver evil on camera? Are Mac 'n' oliver evil on camera? IS a palindrome! Enter a string that you want to check (or enter to exit): CSC220 Data Sructures CSC220 Data Sructures is NOT a palindrome! Enter a string that you want to check (or enter to exit)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started