JAVA programming question using Data Structures

User Generated

ChcclOnex

Programming

CIS 22C

De Anza College

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

Testing a queue of Strings: isEmpty() returns true Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added The Queue size = 9 First Second Third Fourth Fifth Sixth Seventh Eighth Ninth isEmpty() returns false Testing getFront and dequeue: First is at the front of the queue. First is removed from the front of the queue. Second is at the front of the queue. Second is removed from the front of the queue. Third is at the front of the queue. Third is removed from the front of the queue. Fourth is at the front of the queue. Fourth is removed from the front of the queue. Fifth is at the front of the queue. Fifth is removed from the front of the queue. Sixth is at the front of the queue. Sixth is removed from the front of the queue. Seventh is at the front of the queue. Seventh is removed from the front of the queue. Eighth is at the front of the queue. Eighth is removed from the front of the queue. Ninth is at the front of the queue. Ninth is removed from the front of the queue. The queue should be empty: isEmpty() returns true myQueue.getFront() returns null myQueue.dequeue() returns null End of Queue Test Testing a queue of Integers: isEmpty() returns true Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added Successfully added The Queue size = 8 80 70 60 50 40 30 20 10 isEmpty() returns false Testing getFront and dequeue: 80 is at the front of the queue. 80 is removed from the front of the queue. 70 is at the front of the queue. 70 is removed from the front of the queue. 60 is at the front of the queue. 60 is removed from the front of the queue. 50 is at the front of the queue. 50 is removed from the front of the queue. 40 is at the front of the queue. 40 is removed from the front of the queue. 30 is at the front of the queue. 30 is removed from the front of the queue. 20 is at the front of the queue. 20 is removed from the front of the queue. 10 is at the front of the queue. 10 is removed from the front of the queue. The queue should be empty: isEmpty() returns true myQueue.getFront() returns null myQueue.dequeue() returns null End of Queue Test The result of calling equals for the The result of calling equals for the After enqueuing one more, the result After enqueuing one more, the result ArrayQueues = true LinkedQueues = true of calling equals for the ArrayQueues = false of calling equals for the LinkedQueues = false Testing Double LinkedQueue: Testing dequeuing Double LinkedQueue: 1.2 Testing dequeuing Double LinkedQueue: 8.9 Double LinkedQueue's size is 0 Testing equals for empty LinkedQueues returns true Testing enqueuing Double LinkedQueue after emptying: true Double LinkedQueue's size is now 1 Testing Double ArrayQueue: Successfully enqueued 100.0 ArrayQueue size is 1 Successfully enqueued 101.0 ArrayQueue size is 2 Successfully enqueued 102.0 ArrayQueue size is 3 Successfully enqueued 103.0 ArrayQueue size is 4 Successfully enqueued 104.0 ArrayQueue size is 5 Successfully enqueued 105.0 ArrayQueue size is 6 Successfully enqueued 106.0 ArrayQueue size is 7 Successfully enqueued 107.0 ArrayQueue size is 8 Successfully enqueued 108.0 ArrayQueue size is 9 Successfully enqueued 109.0 ArrayQueue size is 10 Unable to enqueue 110.0 Dequeuing 100.0 ArrayQueue size is 10 Unable to enqueue 111.0 Dequeuing 101.0 ArrayQueue size is 10 Unable to enqueue 112.0 Dequeuing 102.0 ArrayQueue size is 10 Unable to enqueue 113.0 Dequeuing 103.0 ArrayQueue size is 10 Testing emptying the ArrayQueue: Dequeuing 104.0 size is now 9 Dequeuing 105.0 size is now 8 Dequeuing 106.0 size is now 7 Dequeuing 107.0 size is now 6 Dequeuing 108.0 size is now 5 Dequeuing 109.0 size is now 4 Dequeuing 110.0 size is now 3 Dequeuing 111.0 size is now 2 Dequeuing 112.0 size is now 1 Dequeuing 113.0 size is now 0 Testing equals for empty ArrayQueues returns true Testing enqueuing Double ArrayQueue after emptying: true Double ArrayQueue now has: 18.0 Double ArrayQueue's size is 1
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

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 ...


Anonymous
Great! 10/10 would recommend using Studypool to help you study.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags