QUOTE(cobrec @ 12 Jul, 2007 - 10:29 PM)

QUOTE(alcdotcom @ 12 Jul, 2007 - 11:17 AM)

Look at your do-while loop in your main method. You have
it = myDatesList.iterator();. So, every time you iterate through that loop that line creates a new Iterator. Your code would work except for this one line. I wonder...should you remove it? Move it somewhere else? Hmmm.

I tried removing the offending line; howvever, it just caused the program to crash when I tried to execute it... the same thing for when I moved it.... I am not sure where to move it to. and I am still lost on how to dequeue.... and my classmates haven't been much help either. Does anyone know where I can find a sample of what I am trying to do??? I looked at another post of an applet... but it used strings, and I couldn't get that example to port into my existing code. I am totally disheartened by this whole assignment...
Cobrec
Think about this for a second. Try to understand why it's adding the same date to the queue each time. Every time you run that line a new iterator is created. When a new iterator is created its internal pointer is on the first element (Date) in the list. So, every time you iterate through the loop, you are effectively resetting the iterator to the first date in the list which is then put into the queue. What you want to do is move the initialization of the iterator outside the do-while loop. You can't just delete the line because then your code is calling it.next() when the iterator's pointer is already at the end, so you'll get an exception. So, put your initialization outside the loop. And, before you try to pull a date from the iterator, make sure you test it to see if it has a next date.
Now, as for enqueueing and dequeueing. You're using a LinkedList which implements the Java
Queue interface. Look at the API link and you'll see that there are 6 methods. You can discount element() and peek() because they only allow you to view an element and don't actually change the state of the queue. So, you're left with a choice of add() and offer() to enqueue and remove() and poll() to dequeue. The pairs are basically the same and only behave differently in certain cases (e.g. when the queue is empty). Look at the API for details.
There's one more bit of OPTIONAL advice I'd give you. If you are creating a class that needs to be sorted (compared) using "natural" ordering then instead of making a comparator for it, you can just make the class implement the Comparable interface.
CODE
public class Date implements Comparable<Date> {
...
...
// must implement this method for Comparable<Date> interface
public int compareTo( Date otherDate) {
...
...
}
...
)
Comparators are good for when you want to either compare a class that you may not be able to modify (like a class written by someone else) or when you want to use an ordering other than the natural ordering. Say, for instance, that your natural ordering (implemented using the Comparable interface) puts Dates in chronological order (from oldest Date to newest Date). What if you want to specify an alternate ordering, say reverse chronological order? Well, you can create a Comparator that does that an pass it in with your list of Dates. You can create any number of alternate orderings, or none at all.