CSC234 - Exam 1


Read all questions before beginning. You will until Wednesday Feb 26 at 8:30am to complete this exam.

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

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

        Queue<Integer> q = new ArrayQueue<Integer>();
        q.add(5);
        q.add(9);
        q.remove();
        q.remove();
        q.add(4);
        q.add(17);
        q.add(58);
        q.add(19);
        q.add(47);
        q.remove();
        q.remove();
        q.remove();
        q.add(5);

Question 2

Write a class in Java to represent a Ceiling Fan. You should have two data members, one to indicate whether the light is on or off, and one to indicate the current speed of the fan, which can be 0, 1, 2, or 3. You should write four methods

Question 3

Implement a Double-Ended Queue (known as a Deque, pronounced "Deck") for the game Focus. Instead of what is listed on the website, use an Array implementation for your Deque.

Use the following Android Focus project instead of the skeleton code linked on the Focus website.

Question 4

Write a method public boolean removeLast(E target) for our LinkedList that will remove the last found instance of the element target. If the element is not found in the LinkedList, return false.