Lab 3 (100 pts)
Due Monday, October 15 at 11:59pm on Canvas

Pair Programming Extra Credit Opportunity (5 pts)

  • Both partners fill in, sign and date the pair programming contract and BOTH partners submit this file.
  • Only one partner submits the lab assignment on Canvas. Please make sure both your names are on ALL the files.
  • Both partners follow the rules for pair programming.

Part 1: Implementing Your Stack and Queue (65 pts)
  • Begin by implementing the Stack and Queue classes as defined in the lesson notes
  • For the Queue class instructions, see Queue Lesson (Lesson 5)
  • For the Stack class instructions, see Stack Lesson (Lesson 6)
  • Note that you must implement all methods whose signatures are provided. No credit for writing any additional methods for these two classes or for altering the class definitions or method signatures, in any way, aside from implementing the required methods
  • Make sure to test all of your methods to ensure that they are working properly in separate test files, named QueueTest.java and StackTest.java (where you should call each method at least two times inside of main as soon as you write it).
  • When you have finished writing the classes, test your methods further by writing JUnit test classes (3 assertEquals statement per class) for each of the following methods:
    • Queue Class:
      • enqueue
      • dequeue
      • getFront
      • getLength
      • isEmpty
      • equals
    • Stack Class:
      • push
      • pop
      • peek
      • getLength
      • isEmpty
      • equals
  • Once you are satisfied that your methods are working properly (passing all JUnit tests and the tests you wrote in QueueTest.java and StackTest.java), move on to part 2 below.


Part 2: Palindrome Tester (35 pts)

  • This is a common interview question!
  • Using a Stack and a Queue, determine whether a String is a palindrome (a word spelled the same both forwards and backwards).
  • Create a new text file called palindrome.txt and save it in the same Lab3 folder along with your Queue.java and Stack.java classes.
  • Copy and paste the following contents into palindrome.txt:
A man, a plan, a canal, Panama.
Do geese see God?
Never odd. Even.
Never odd or even.
Eye
Ear
Able was I ere I saw Elba!
Was it Eliot's toilet I saw?
Race cars
Dammit, I’m mad!
On a clover, if alive, erupts a vast, pure evil; a fire volcano.
Nurses run.
Madame, not one man is selfless; I name not one, madame.
Madame, not one man is selfless; I name not one, madam.


  • Next, open a new Java class called Palindrome.java in the Lab 3 folder.
  • Copy and paste the below starter code into this file:
/**
 * Palindrome.java
 * @author
 * @author
 */

import java.io.IOException;
import java.io.File;
import java.util.Scanner;

public class Palindrome {
   
   
    public static void main(String[] args) throws IOException {
        Queue<Character> Q = new Queue<Character>();
        Stack<Character> S = new Stack<Character>();
       
        File file = new File("palindrome.txt");
        Scanner input = new Scanner(file);
        String line;
       
//Write the rest of your code here
     
        input.close();
    }//end of main

}

  • Complete the program to test each phrase in palindrome.txt to see if it is a palindrome.
  • For credit, you must use only the given Queue and Stack of Characters to solve this problem.
  • You are not allowed to use any additional structures, including any additional Queue(s) or Stack(s).
  • In other words, you must use only 1 Stack and 1 Queue in your solution to this problem in order to receive credit for this assignment - and this Stack and Queue must store Characters.
  • Print out your results to the console, like what is shown below in the next section.
    • Indicate in parenthesis next to each phrase whether or not it is a palindrome as shown below


Your Program Should Give Indentical Output to the Following:

A man, a plan, a canal, Panama. (Palindrome)
Do geese see God? (Palindrome)
Never odd. Even. (Not Palindrome)
Never odd or even. (Palindrome)
Eye (Palindrome)
Ear (Not Palindrome)
Able was I ere I saw Elba! (Palindrome)
Was it Eliot's toilet I saw? (Palindrome)
Race cars (Not Palindrome)
Dammit, I’m mad! (Palindrome)
On a clover, if alive, erupts a vast, pure evil; a fire volcano. (Palindrome)
Nurses run. (Palindrome)
Madame, not one man is selfless; I name not one, madame. (Not Palindrome)
Madame, not one man is selfless; I name not one, madam. (Palindrome)

Specifications for Submission:

  • Submit your Queue.java, Stack.java, and Palindrome.java to Canvas, as well as QueueTest.java, StackTest.java and the required unit tests (please see above).
  • Optional: Submit your pair programming contract to Canvas (both partners).
  • Please do *not* submit your files as a zip or you will receive a 5 point deduction

How You Will Be Graded:

  • 2.5 points per correct Queue and Stack method
  • 8 points for the QueueTest.java and StackTest.java files where each method is called at least twice.
  • 12 points for the required 12 JUnit tests (assertEquals called three times per class)
  • 35 points for a fully functional Palindrome.java class