CS1027b Computer Science Fundamentals II

Lab 9

Learning Outcomes

Upon completion of this lab, you should be able to do the following:

General Lab Instructions

IMPORTANT. Submit the .java files that you write for this lab and AnswersLab9.txt through OWL by 11:55pm on Friday, March 20.

Exercise 1: Implementing a Queue with a Circular Array

Download CircularArray.java, QueueADT.java, and EmptyCollectionException.java from the Sample code page of the course's website.
Class CircularArrayQueue implements a queue using a circular array. In this class there are 4 instance variables:

1. There are two compilation errors in method expandCapacity. 2. Complete method first. This method should throw an EmptyCollectionException if the queue is empty. Otherwise it must return the first data item in the queue without removing it.

3. Download TestCAQ.java and run it; enter test number 1 when prompted. The program must print a message stating that your implementation passed the testing for method "first". If you get a message indicating that the test for this method was unsuccessful, use the debugger to find the error(s) and fix it(them).

4. Run the program testCAQ again and this type enter test number 2. 5. Run the program again, but this time choose test 3. The test will fail. 6. Run the program again and choose test 4. The program will crash. 7. Complete method toString. It must return a string of the form "QUEUE: data_1, data_2, ..., data_n", where "data_1" is the data item at the front of the queue and "data_n" is the data item at the rear of the queue.