Overview | Schedule | Announcements | Resources | Assignments | Home |
Do |
Create an empty Queue class by opening the class editor (double-click the Queue class diagram) and create the class shell: import java.util.ArrayList; /** * Queue (waiting line). * * @author <Your Name Goes Here> * @version <Today's Date Goes Here> */ public class Queue { } Add the private fields: ArrayList entries and int maxLengthEver Create the class constructor: It will create an instance of entries and set maxLengthEver to 0. maxLengthEver represents the largest the queue ever becomes during its lifetime. Write the methods enqueue and dequeue: Customer objects will be added to and removed from the queue. The customer class here has only one field, a customerID. This is different from the customer object you will use in project 3, which you will see in class. Open the Customer class in an editor window. Take a few minutes to examine its methods before continuing to the next step.
Write the method size: size() simply returns the size of the queue as an int. |
Test |
Now test enqueue and dequeue as follows: Create three Customer objects, one with customerID = 1, another with customerID = 2, and the third with customerID = 3. Next create an instance of your Queue class and envoke enqueue three times, adding a different customer object each time. When the dialog box appears to request the customer to enqueue, just left-click once on the customer you want to add. Check the size of the queue. Now dequeue and enqueue as you wish, checking the size of the queue each time to make sure the number of items in the queue is correct. When you are satisfied that things are working correctly, proceed to the next step. |
Do |
Add the method isEmpty: isEmpty is a boolean method that returns true if the queue has no elements and false otherwise. Test the method before going on to the next step. Write two display methods, printStatistics and display:
|
Overview | Schedule | Announcements | Resources | Assignments | Home |
DePauw
University , Computer Science
Department , Spring 2005
Maintained by Brian
Howard ( bhoward@depauw.edu
).
Last updated