Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
The problem is while storing into the priorityqueue, not while printing. I am assuming that while storing into the queue, it stores in a sorted manner.
JavaDoc says about PriorityQueue:
[javadoc]
public class PriorityQueue<E>
extends AbstractQueue<E>
implements Serializable
An unbounded priority queue based on a priority heap. "The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used". A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException). [/javadoc]
Is my constructor wrong or my assumption about Queue construction is wrong?
No, the way you're retrieving data from the queue is wrong. I already told you that you're accessing the elements from the queue using an enhanced for loop, and I asked you whether you know how the enhanced for loop works.