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
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.
add
an object to the queue, if the queue is already filled to capacity
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:
add
,
toString
.
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.
Get help if you’re stuck. This exercise is intended to take about 25 minutes in class.
FixedLengthQueue
project from your repository.
FixedLengthQueueTest
is a JUnit test class; we’ll use this in grading your work.
TestFixedLengthQueue
has a main()
method that you may find useful for experimenting. Here’s what its output should be when you’ve implemented the data structure correctly: ---------- Queue length = 3 I I heard I heard it heard it through it through the through the grapevine. ---------- Queue length = 4 I I saw I saw her I saw her again saw her again last her again last night. Exception occurred as expected.
TODO
items in FixedLengthQueue.
FixedLengthQueue
whose capacity is less than 1.
Remember, in all your code:
Here is the grading rubric for this assignment.
Turn in your work by committing it to your SVN repository.