DynamicList/LinkedList Queue Implementation
clear() is buggy

The following code causes a NoSuchElementException:

DynamicQueue queue = new DynamicQueue();
queue.offer("First");
queue.clear();
queue.offer("First");
queue.poll();


You can ealy fix it by adding tail = null; to your clear() method.

Use selfexplaing exception messages

An exception name (in this case NoSuchElementException) already describes the kind of error accurred. The cause should explain why this happened. A better message for exaple could simply be "this queue is empty".

Suggestion: add a return type to poll()

If poll() returns the current head, the user doesn't need to do call peek(). This wouldn't even change your main(String[]), since the user is not forced to use the returned object at all.



Of course, you could also add a generic type to your class instead of using Object inside your Node, but I guess that was not your intension, since you are already familiar with the Java Collections.