CSC234 - Exam 1

Assigned Feb 25th 1pm
Due Feb 28th, 8am


Read all questions before beginning. You will have 48 hours from when you begin this exam until you must finish working. The exam must be completed by 8am Feb 25th, 2010. You are not allowed to use the internet in general for this exam, only what is linked from this page and the Java API. You may use the computer to compile and test your Java code. You are bound by the Honor Code for this exam, which you need to sign. Show your work on all problems for full credit.

Create a directory on the cs.centenary.edu server called exam1, and copy your solutions there.

Question 1

Implement a version of the Queue<E> interface using two ArrayStack<E> as your only data members. You can use the files Queue.java, Stack.java and ArrayStack.java from the book code. You should turn in a file called SQueue.java, of which the basic template is provided for you.

Draw a diagram showing the internal representation of the data members of the SQueue when executing the code in the main method provided.

Question 2

Using an ArrayStack, write a static method called isMatch(String s) in the Java file called MatchingParens.java. This method brings in a String and will return true if every left parenthesis has a matching right bracket, and they are properly nested, otherwise return false. When you encounter a left parenthesis, push it on the Stack, and when you encounter a right parenthesis, it must match the top of the Stack and pop it off or the String is invalid. The parenthesis you must test are "<" and ">", "(" and ")", "{" and "}", and "[" and "]". Your code should work correctly on the test cases provided. You must add two cases of your own, one which should return true, one which should return false.

Question 3

Write a program Repeats.java that reads in a sequence of integers and printsout the integer that appears the most times in-a-row. For example, if the input is 1 2 2 1 5 1 1 7 7 7 7 1 1 then your program should print out the integer 7. Your code should work correctly on the test cases provided. You must add two cases of your own.