Question
} // This class provides method to test if a string is a Palindrome using Stack/Queue ADTs. // Csc20 lab 7 assignment // Csc20's student
}
// This class provides method to test if a string is a Palindrome using
Stack/Queue ADTs.
// Csc20 lab 7 assignment
// Csc20's student to provide more inputs here.
import java.util.Stack;
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
class Palindrome {
// This is a main method to test checkPalindrome method
public static void main(String[] args) {
String inputString = new String("");
Scanner in = new Scanner(System.in);
do {
// please put your code to test checkPalindrome method here
} while ( inputString.equals("y") && inputString.length() ==
1 );
System.out.print("Bye!");
}
// This is checkPalindrome method. It checks if an input string is
Palindrome or not.
// It returns 0 if a string is a Palindrome. Otherwise, it returns a
position of a character where it finds
// a different value.
// Pre-Condition: string must not be null.
// Post-Condition: Return 0 if input string is a Palindrome. Return a
positive number indicate the location where
// a difference found.
public static int checkPalindrome(String strValue) {
Stack
Queue
// check if string is null. If it is null, return a -1
// normalize the string values to lower case, remove spaces
strValue = strValue.toLowerCase().replaceAll("\\W", "");
// store data on stack/queue adts first
// loop: comparing, retrieving text, terminate loop if stack is
emptied or found a difference
return indexVal;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
/** Unit test cases for checking the Palindrome method **/
/** Doan Nguyen: CSC 20 - Spring 2018 **/
import org.junit.Assert;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class PalindromeTest {
/** Fixture initialization (common initialization
* for all tests). **/
String testStr = new String("");
@Before public void setUp() {
testStr = "";
}
/** Step on no pets test. **/
@Test public void defaultTest() {
testStr = "Step on no pets";
int check = Palindrome.checkPalindrome(testStr);
assertEquals(0, check);
}
/** null test. **/
@Test public void nullTest() {
testStr = null;
int check = Palindrome.checkPalindrome(testStr);
assertEquals(-1, check);
}
/** BelphegorPrime number test. **/
@Test public void BelphegorPrimeTest() {
testStr = "1000000000000066600000000000001";
int check = Palindrome.checkPalindrome(testStr);
assertEquals(0, check);
}
/** fail lonely tylenol test. **/
@Test public void failTest() {
testStr = "Lonely Tvlenol";
int check = Palindrome.checkPalindrome(testStr);
assertEquals(6, check);
}
}
E aO 2Pac - I Get AroundHome | My Sac State Mail-sergiozavala@csus.t Files CSC20-lab7 pdf file ///C/Users/Owner/AppData Local/Packages/MicrosoftMicrosoftEdge 8 wekyb3d8bbwe TempState Downloads/cs20ab7.pdf Lab work (in school laboratory): There are different algorithms to determine if a string is a palindrome Our work in this lab uses Stack and Queue ADTs. Here is an approach: Read the input string one character at a time Push a copy of a character on to the stack. Add the same character to (the back of the) queue When the line has been entirely read, the program repeatedly compares the top of element of the stack and the front element of the queue; in case of a match, it pops the stack and (simultaneously) de- queues the queue If ever there is a mismatch between the top element of the stack and the front element of the queue, the program declares that the input string is not a palindrome, and halts. The program also reports a position where a different text found If the stack (orequally correctly, the queue) gets empty, the program declares that the given string is a palindrome, and stops Because of the high importance of a stack and a queue as data structures in computer science, Java includes their implementation in the java.util package (http://docs.oracle.com/javase/7/docs/api/java/util/package- summary.html). The Stack is a class. Queue is an interface (we will discuss interface). Since Queue is an interface, you need to :0 PM Type here to search 3/24/2018 2
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