CSSE 220 – Object-Oriented Software Development

Fixed Length Queue In-Class Exercise

Objectives

The FixedLengthQueue abstract data type that you will implement today is for practice in implementation.  In the Past, it has been part of the Markov programming project in CSSE 220

Description

 

A "fixed length queue" is a very simple abstract data type. It behaves (sort of) like a queue that holds Objects. When constructed, it is given a fixed capacity, and it initially contains no objects.

There is no explicit remove operation. Perhaps it should be there, but it is not part of this assignment due to time constraints.

The only other public operation besides add is toString, which simply calls each object’s toString method, and concatenates all of the resulting strings (in queue order of course), separated by a space.

Thus you only have three public methods to implement:

A FixedLengthQueue should be implemented using an array, so only a fixed amount of space is ever allocated for a given queue. The add method should be a constant-time operation (i.e. the running time for this method should not depend on the capacity of the queue, as evidenced by no loops or recursive calls in its code). Hint: treat the array as a circle. The % (mod) operator may be helpful here.

Tasks

Get help if you’re stuck. This exercise is intended to take about 25 minutes in class.

  1. Check out the FixedLengthQueue project from your repository.
  2. Notice that two test classes are provided:
  3. Complete the TODO items in FixedLengthQueue.
  4. Add code to the constructor to prohibit construction of a FixedLengthQueue whose capacity is less than 1.

Remember, in all your code:

Here is the grading rubric for this assignment.

Turn-in Instructions

Turn in your work by committing it to your SVN repository.