Consider strings that can be split so that their first half is the same as their...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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<T> 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<t>( /** 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<T> implements QueueInterface<T> 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<String> myQueue = new ArrayQueue<String> (); 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.") : 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<T> 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<t>( /** 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<T> implements QueueInterface<T> 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<String> myQueue = new ArrayQueue<String> (); 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.") :
Expert Answer:
Answer rating: 100% (QA)
Required solution public class ArrayQueue implements QueueInterface private T queue circular array o... View the full answer
Related Book For
Cornerstones of Managerial Accounting
ISBN: 978-0324660135
3rd Edition
Authors: Mowen, Hansen, Heitger
Posted Date:
Students also viewed these accounting questions
-
The net present value is the same as the profit of a project expressed in present dollars. Do you agree? Explain.
-
The period of the Moons rotation is the same as the period of its revolution: 27.3 days (sidereal). What is the angular momentum for each rotation and revolution? (Because the periods are equal, we...
-
The situation is the same as described in Prob. 7.6- 1 except that Wyndor management does not consider the additional information about the rumor to be reliable. Therefore, they havent yet decided...
-
One of the key aspects of the Risk Management Process which the Health Care Providers should be using as an essential tool is risk modeling. It can be argued that for the sustainability of the Health...
-
How can you measure problem recognition?
-
A firm is considering the following alternatives, as well as a fifth choice: do nothing. Each alternative has a 5-year useful life. The firm's minimum attractive rate of return is 8%. Which...
-
James Lewis, a resident of Kentucky, sustained an injury while operating a Caterpillar bulldozer. He filed suit against Caterpillar, a company incorporated in Delaware but with its principal place of...
-
You have been given the expected return data shown in the first table on three assets'F, G, and H'over the period 20132016. Using these assets, you have isolated the three investment alternatives...
-
Tl-208 decays through a beta emission and has a half-life of 3.05 minutes. Besides the beta emission, there are several gamma rays associated with the decay and these gamma emissions occur at...
-
How could B/C analysis be used to help determine the level of subsidy to be paid to the operator of public transportation services in a congested urban area?
-
Reaction 1 and Reaction 2 can be described by the following equations: Reaction 1: NaOH(s) Na (aq) + OH (aq) Reaction 2: NaOH(s) + H (aq) + CI (aq) Na+ (aq) + Cl (aq) + HO(1) Multiply, divide, or...
-
Whole Pine Inc. s average collection period ( ACP ) is 6 0 days. The company recently generated $ 2 1 5 , 0 0 0 from sales of partial pine parts to part - time pine enthusiasts. What is the company s...
-
what ways does the intersection of art and technology catalyze socio-cultural transformations, reshaping modes of artistic production, dissemination, and reception, and redefining the boundaries...
-
Discuss the correlation between principles and natural law. Note: Explain the question with respect of the philosophy of law, you can use online sources or other references to support your...
-
What is the proper role of the Prosecutor in the criminal justice system? What are some problems that prosecutors face in properly and ethically performing their function? What steps can be taken to...
-
You invested $60,000 in a mutual fund last year. At the time you opened your account, the mutual fund shares had a NAV of $70. The fund charges a 2% front-end load and a 1% back-end load. During the...
-
Fran is a CPA working for a regional accounting firm. Xavier Corp was incorporated January 1, 2022, and desired to elect S corporation status at inception. Fran filed Form 1120-S for Xavier for 2022...
-
Sundial Technologies produces and sells customized network systems in New Brunswick. The company offers a 60-day, all software and labor-and an extra 90-day, parts-only- warranty on all of its...
-
Responsibility for the materials price variance typically belongs to a. production. b. marketing. c. purchasing. d. personnel. e. the chief executive officer (CEO).
-
Suppose that the accounts receivable turnover ratio of a company is low when compared with other firms within its industry. How would this information be useful to the managers of a company?
-
Refer to the Farnsworth Company information in Problem 3-41 for the first 10 months of data on receiving orders and receiving cost. Now suppose that Tracy has gathered two more months of data: For...
-
Oxford Corporation began operations in 2015 and reported pretax financial income of 225,000 for the year. Oxfords tax depreciation exceeded its book depreciation by 40,000. Oxfords tax rate for 2015...
-
At December 31, 2015, Suffolk Corporation had an estimated warranty liability of 105,000 for accounting purposes and 0 for tax purposes. (The warranty costs are not deductible until paid.) The...
-
State whether each of the following events will result in a movement along General Motors (GMs) demand curve for labor in their U.S. automobile factories or whether it will cause its demand curve for...
Study smarter with the SolutionInn App