Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Consider strings that can be split so that their first half is the same as their second half (ignoring blanks, punctuation, and case). For

  

 public class ArrayQueuesT? implements QueueTnterfacesTs private Ti queue:|/7 circular array of queue entries and one unused l 

Page // end enqueue public T getFront )( T front - null; if (isEmpty)) front = queue [frontIndex); return fronti 1 // end get 

queue [index] oldQueue [frontIndex); frontIndex- (frontIndex + 1) % olds íze; // end for front!ndex back!ndex = 0; oldSize 2;

 

public class QueueTest public static void main (Stringl] args) ( Arra yQueue<String>(); QueueInterface<String> myQueue myQueu  

Consider strings that can be split so that their first half is the same as their second half (ignoring blanks, punctuation, and case). For example, the string "booboo" can be split into "boo" and "boo". Another example is "hello, hello". After ignoring blanks and the comma, the two halves of the string are the same. However, the string "rattan" has unequal halves, as does the string "abcab". Add a method public static boolean check(String s) to the class Array Queue (your function must be in the file Array Queue.java) that returns true when s has the property above and false otherwise. You must use methods from Queuelnterface.java and Array Queue.java. Do not use stacks or recursion. P2 (60 points) Part 1 - In this problem, we will add new methods to the class ArrayQueue Suppose that we want to add a method to a class of queues that will splice two queues together. This method adds to the end of a queue all items that are in a second queue (making the second queue empty). The header of the method could be as follows: public void splice(Queuelnterface anotherQueue) Write this method for the class ArrayQueue Part 2 - Add the method public boolean enqueueNoDuplicate(T item) which adds item if it is not already in the queue. If item is already present, no change to the queue takes place and the method returns false. Otherwise, the method returns true. public interface Queuetnterface ( /** Adds a new entry to the back of this queue. @paran newEntry an object to be added / public void enqueue (T newEntry) y* Removes and returns the entry at the front of this queue. Breturn either the object at the front of the queue or, if the queue in empty before the operation, null / public t dequeue () 1.Retrieves the entry at the front of this queue. Breturn either the object at the front of the queue or, if the queue is empty. null / publie T getFront () 1Detects whether this queue is empty. Ereturn true it the queue is empty, or false otherwise publie boolean isimpty ( 1Removes all entries from this queue. / public void clear ( /end QueueIntertace public class ArrayQueue implements QueueInterface private T0 queue; // circular array of queue entries and one unused location private int frontIndex; private int backIndex; private static final int DEFAULT INITIAL CAPACITY =50; public ArrayQueue () { this (DEFAULT INITIAL CAPACITY); /end default constructor public ArrayQueue (int initialCapaeity)t / the cast is safe because the new array contains null entries @SuppressWarnings ("unchecked") T() tempQueue - (TI) new ObjecE [initialCapacity + 1: queue = tempQueue: frontIndex 0; backIndex / end constructor initialCapacity: public void enqueue (T newEntry)E ensureCapacity (): backIndex - (backindex + 1) queue.length: queue(backIndex) = newEntry: / end enqueue public T getEront () ( TEront null: iE (lisEmptyU) front - queue [frontIndex]: return front: 17/end get Front public T degueue () I front nuli: Ir (1sEmpty ()) front queue ErontIndexl MacBook Air Page 1 // end enqueue public T getFront () ( T front = null; if (!isEmpty 0Y front = queue [frontIndex]; return front; 1 // end getFront public T dequeue () { T front = null; if (lisEmpty () front = queue [frontIndex]; queue (frontIndex] - null; frontIndex (frontIndex + 1) % queue.length; } // end if return front; } // end dequeue private void ensureCapacity () ( if (frontIndex == ( (backIndex + 2) queue.length)) is full, ( // if array TI) oldQueue - queue; int oldsize = oldQueue.length; @SuppressWarnings ("unchecked") TIJ tempQueue = (T[]) new Object [2 * oldsize]; queue - tempQueue; for (int index - 0; index < oldsize -1; index++) oldQueue [frontIndex]; queue (index] frontIndex = (frontIndex + 1) % oldsize; }// end for %3! frontIndex = 0; backIndex = oldSize 2; Y// end if 1 // end ensureCapacity public boolean isEmpty () ( ( (backIndex + 1) * queue.length); return frontIndex == } // end isEmpty public void clear () { if(!isEmpty (0) for (int index = frontIndex; index !- backIndex; index = (index+1) queue.length) queue (index] = null; queue (backIndex] - null; frontIndex - 0; backIndex - queue.length 1//end ArrayQueue public class QueueTest{ public static void main (String[] args) { QueueInterface myQueue = new ArrayQueue (); myQueue.enqueue ("Jim"); myQueue.enqueue ("Jess"): myQueue.enqueue ("Jill"); myQueue.enqueue ("Jane"); myQueue.enqueue ("Joe"); String front = System.out.println (front +" 1s at the front of the queue."); myQueue.getFront (); // returns "Jim" myQueue.dequeue (); // removes and returns "Jim"; is removed from the queue. "); front = System.out.printin (front + myQueue.enqqueue ("Jerry"): front = myQueue.getFront (); returns Jess" System.out.println (front + " is at the front of the queue."); front = myQueue.degueue ():/ removes and returns "Jess"; System.out.printin(front "is removed from the queue.") :

Step by Step Solution

3.40 Rating (147 Votes )

There are 3 Steps involved in it

Step: 1

Required solution public class ArrayQueue implements QueueInterface private T queue circular array o... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Document Format ( 2 attachments)

PDF file Icon
635e37f46f220_182455.pdf

180 KBs PDF File

Word file Icon
635e37f46f220_182455.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cornerstones of Managerial Accounting

Authors: Mowen, Hansen, Heitger

3rd Edition

324660138, 978-0324660135

More Books

Students explore these related Accounting questions