CS210: Intermediate Computing/Data Structures (Java)
This lab gives you
experience developing a class that implements a queue using a circular
array. In this lab, you will handle the
possibility of needing to expand capacity.
The test case code provided in this lab does test your code for its
behavior in that situation.
Prior to the lab session, do
the following to get started:
save, and unzip the file Lab6.zip on your removable media
(floppy disk, Zip disk, or memory stick) creating a directory named Lab5.
your CircularArrayQueue class from Lab5 into this directory.
the Dr Java Application on your PC.
a new Dr Java project in the Lab6 directory by selecting the menu Project
-> New… naming the project file Lab6 and saving it in your new Lab6
directory. (Dr Java automatically opens
file in the editor window which you will ignore.)
the menu File-> Open, open the files: CircularArrayQueue.java, EmptyCollectionException.java,
QueueADT.java, and QueueTest.java.
Dr Java will automatically include this source file in the Project. Use the menu Project -> Save to
save the updated project file.
Study the lecture notes
about the expand capacity problem for the CircularArrayQueue class so that you
understand what it needs to do.
need to design and add code to the methods of the CircularArrayQueue class in
places as indicated by the comments:
1. In the enqueue method, you need to add a check for
the need to expand capacity before updating the queue array and if needed, call
the private expandCapacity method.
2. In the private expandCapacity method, you need to add
the code to instantiate a new array twice the size of the existing array and
copy all of the contents of the smaller array into the larger array so that the
next element can be added.
Using the menu Project -> Compile Project,
compile the program. Test your code by
selecting the TestQueue.java file and using the DrJava Tools -> Test Current
Document menu. This will run one
different JUnitTestCase on your implementation of the CircularArrayQueue class
to verify that your code now handles the expandCapacity situation correctly.
Show your code to the TA
before leaving the lab. When you are
through with the lab, close the Project using the menu Project -> Close. Be sure to remove your media and take it with
you. If you have not finished the code,
finish it by the next lab period. You
will need to add to this code in the next lab to handle expand capacity.
Before you leave, have your TA check your
code in progress. If you have not
completed it, finish it before the next lab session to include a hard copy with
your lab report.
Write a document that
answers the following questions. Your lab must be printed (not
Answer the following
questions related to what you did in this week’s lab.
Note: You should work alone on the lab report.
assignment is due at the BEGINNING of your next lab. No late assignments
will be accepted. Emailed assignments will not be accepted. If you
are not going to be in lab on the due date, you can turn the assignment ahead
of time to the CS210 TA box in the CS department office.