Question: Assignment: (Class options pasted below) PLEASE ENSURE THE PROGRAM RUNS WITHOUT ERRORS. A palindrome is any word, phrase, or sentence that reads the same forward

Assignment: (Class options pasted below) PLEASE ENSURE THE PROGRAM RUNS WITHOUT ERRORS.

A palindrome is any word, phrase, or sentence that reads the same forward and backward. For example:

Able was I ere I saw Elba Desserts I stressed Kayak abcde edcba

Write a program that uses a stack to determine if a string of characters is a palindrome. This program will ask the user to enter a string, then printout a statement indicating whether or not the string was a palindrome.

Your program should treat all letter characters as lower case. Remember, spaces are characters also.

You may use any data structure you wish to create the stack so long as the stack is implemented and used correctly. Do not use any of classes in the Java API. You may use any of the class files in the wk4.zip file.

Name your demo class (containing the main method) PalindromeDemo.

/** An interface for the ADT stack. @author Frank M. Carrano @version 4.0 */ 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

import java.util.EmptyStackException; /** A class of stacks whose entries are stored in a chain of nodes. @author Frank M. Carrano and Timothy M. Henry @version 4.0 */ public class LinkedStack implements StackInterface { private Node topNode; // References the first node in the chain public LinkedStack() { topNode = null; } // end default constructor // < Implementations of the stack operations go here. > // . . .

private class Node { private T data; // Entry in stack private Node next; // Link to next node private Node(T dataPortion) { this(dataPortion, null); } // end constructor private Node(T dataPortion, Node linkPortion) { data = dataPortion; next = linkPortion; } // end constructor private T getData() { return data; } // end getData private void setData(T newData) { data = newData; } // end setData private Node getNextNode() { return next; } // end getNextNode private void setNextNode(Node nextNode) { next = nextNode; } // end setNextNode } // end Node } // end LinkedStack

/** A class of stacks whose entries are stored in an array. @author Frank M. Carrano and Timothy M. Henry @version 4.0 */ public class ArrayStack implements StackInterface { private T[] stack; // Array of stack entries private int topIndex; // Index of top entry private boolean initialized = false; private static final int DEFAULT_CAPACITY = 50; private static final int MAX_CAPACITY = 10000; public ArrayStack() { this(DEFAULT_CAPACITY); } // end default constructor public ArrayStack(int initialCapacity) { checkCapacity(initialCapacity); // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] tempStack = (T[])new Object[initialCapacity]; stack = tempStack; topIndex = -1; initialized = true; } // end constructor // < Implementations of the stack operations go here. > // < Implementations of the private methods go here; checkCapacity and // checkInitialization are analogous to those in Chapter 2. > // . . . } // end ArrayStack

import java.util.Vector; /** A class of stacks whose entries are stored in a vector. @author Frank M. Carrano and Timothy M. Henry @version 4.0 */ public class VectorStack implements StackInterface { private Vector stack; // Last element is the top entry in stack private boolean initialized = false; private static final int DEFAULT_CAPACITY = 50; private static final int MAX_CAPACITY = 10000; public VectorStack() { this(DEFAULT_CAPACITY); } // end default constructor public VectorStack(int initialCapacity) { checkCapacity(initialCapacity); stack = new Vector<>(initialCapacity); // Size doubles as needed initialized = true; } // end constructor // < Implementations of checkInitialization, checkCapacity, and the stack // operations go here. > // . . . } // end VectorStack

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!