Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Exception classes: StackException, EmptystackException. FullstockException Pr

ID: 3850302 • Letter: 7

Question

7. Exception classes: StackException, EmptystackException. FullstockException Program #3 1, Show the LinkedtStackADT T interface 2. Create a LinkedstackDs with the following methods: default constructor, overloaded constructor, copy constructor, isEmptystack, push, peek, pop 3. Create a private inner StackNode T> class with the following methods: default constructor, overloaded constructor, toString 3. Exception classes: StackException, stackunderflowException, StackOverflowException 4. Create a Palindrome Demo class that instantiates a LinkedstackDs Character object. Execute a do-while loop that asks the user using dialog boxes to "Input a string for Palindrome Test:" Use the replace All method to remove all blanks and special characters from teststr. output whether or not it is a palindrome in a dialog box. [Use the inputs given on the other handout sheet for testing 5

Explanation / Answer

The required code as per the requirements are as follows. The code refers to every demand made in the question. Here comes the code:

PalChecker.java

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.Scanner;
import java.io.*;
public class PalChecker
{
public static void main(String[] args) throws IOException
{
BufferedReader ip=new BufferedReader(new FileReader("StoryWirtel.txt"));
PrintStream op=new PrintStream(new File("PalChecker.txt"));
boolean checkForPalindrome;
String values,traverse;
values=ip.readLine();
while(values!=null)
{
if (checkForPalindrome(values))
op.println(values+" is a PalChecker");
else
op.println(values+" is not a PalChecker");
values=ip.readLine();
}
}

//Returns the value for the palindrome program

public static boolean checkForPalindrome(String values)
{
Queue<Character> lq = new LinkedList<Character>( );
Stack<Character> st = new Stack<Character>( );
Character first; // Taking character from values
int notPal = 0; // Places which mismatched for palindrome
int index; // Indexing for the values String
for (index = 0; index < values.length( ); index++)
{
first = values.charAt(index);
if (Character.isLetter(first))
{
lq.add(first);
st.push(first);
}
}
while (!lq.isEmpty( ))
{
if (lq.remove( ) != st.pop( ))
notPal++;
}
// If mismatching is found then the string is a palindrome
return (notPal == 0);
}
}

Please rate the answer if it helped....Thankyou

Hope it helps....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote