Description
HW #2 CODE FILE (UPDATED)
REMEMBER, DON'T CHANGE ANY GIVEN CODE UNLESS SPECIFIED!IF YOU WANT TO ADD ANTHING ELSE, YOU MUST ASK THE INSTRUCTOR FIRST OR YOU MAY GET POINTS OFF!
in the LinkedQueue and ArrayQueue classes add and complete the equals method as described below:
@Override
public equals( Object obj )
in LinkedQueue:
compare corresponding elements in this' list to the parameter's list ONLY IF THE PARAMETER IS AN INSTANCEOF LinkedQueue (best to check if the sizes are the same first).DON'T CHANGE ANYTHING in either LinkedQueue, so don't call dequeue nor enqueue OR POINTS OFF!Make sure you compare the data (T) using its equals method!
in ArrayQueue:
compare elements in this' array to the parameter's array ONLY IF THE PARAMETER IS AN INSTANCEOF ArrayQueue (make sure STARTING AT THE FRONT OF THE this' queue array AND the FRONT OF THE PARAMETER'S queue array (they don't have to have the same front index to be equal).DON'T CHANGE ANYTHING in either ArrayQueue, so don't call dequeue nor enqueue OR POINTS OFF. Make sure you compare the data (T) using its equals method!
// you MUST call this method at the end of main
//put this method in the driver class exactly as it's written
// (must not change it):
public static void extraQueueTester()
{
LinkedQueue<Double> doubQueue = new LinkedQueue<>();
doubQueue.enqueue(new Double(1.2));
doubQueue.enqueue(new Double(8.9));
System.out.println("\nTesting Double LinkedQueue: ");
System.out.println("Testing dequeuing Double LinkedQueue: " + doubQueue.dequeue());
System.out.println("Testing dequeuing Double LinkedQueue: " + doubQueue.dequeue());
System.out.println("Double LinkedQueue's size is " + doubQueue.size());
System.out.println("Testing equals for empty LinkedQueues returns "+
doubQueue.equals(new LinkedQueue<Double>()));
System.out.println("Testing enqueuing Double LinkedQueue after emptying: " +
doubQueue.enqueue(new Double(3.4)) );
System.out.println("Double LinkedQueue's size is now " + doubQueue.size());
System.out.println("\nTesting Double ArrayQueue: ");
ArrayQueue<Double> doubQueue2 = new ArrayQueue<>();
for( int i = 0; i < 14 ; ++i )
{
if(doubQueue2.enqueue(100.+i)) // uses autoboxing
System.out.println("Successfully enqueued " + (100.+i));
else
{
System.out.println("Unable to enqueue "+(100.+i));
System.out.println("Dequeuing " + doubQueue2.dequeue());
doubQueue2.enqueue(100.+i);
}
System.out.println("ArrayQueue size is " + doubQueue2.size());
}
System.out.println("Testing emptying the ArrayQueue:");
while( !doubQueue2.isEmpty() )
System.out.println("Dequeuing " + doubQueue2.dequeue() +
" size is now " + doubQueue2.size());
System.out.println("Testing equals for empty ArrayQueues returns "+
doubQueue2.equals(new ArrayQueue<Double>()));
System.out.println("Testing enqueuing Double ArrayQueue after emptying: " +
doubQueue2.enqueue(18.0) );
System.out.println("Double ArrayQueue now has: " + doubQueue2.peekFront());
System.out.println("Double ArrayQueue's size is " + doubQueue2.size());
} // end extraQueueTester
Unformatted Attachment Preview
Purchase answer to see full attachment
Explanation & Answer
Please ignore the above two files. Below attached are the final versions of the files.
/**
A class that implements the ADT queue by using an expandable
circular array with one unused location after the back of the queue.
@author Frank M. Carrano
@author Timothy M. Henry
@version 4.1
UPDATED BY C. Lee-Klawender
*/
public final class ArrayQueue implements QueueInterface
{
private T[] queue; // Circular array of queue entries
private int frontIndex; // Index of front entry
private int backIndex; // Index of back entry
private int count;
private static final ...