Question: Help with this one would be greatly appreciated. Please write the code in an organized manner. Thank you for your help! Queue of distinct strings

Help with this one would be greatly appreciated. Please write the code in an organized manner. Thank you for your help!

Help with this one would be greatly appreciated. Please write the codein an organized manner. Thank you for your help! Queue of distinctstrings Abstract Concept of a queue of distinct strings: A queue of

Queue of distinct strings Abstract Concept of a queue of distinct strings: A queue of distinct strings, p, is a collection of strings with a front and end where a string cannot exist more than once in the collection. For example, the collection of strings ("ab, cd", "ae", "bd) is a queue with front = "ab and end = "hd". The only operations supported are addition of a string at the end known as enqueue, and deletion of a string from the front known as dequeue. Implementation of a queue of distinct strings: The following class, QueueOfDistinctStrings, represents a queue of distinct strings. import java.util.ArrayList; public class QueueOfDistinctStrings { // Overview: QueueOfDistinct Strings are mutable, bounded // collection of distinct strings that operate in // FIFO (First-In-First-Out) order. // The abstraction function is: // a) Write the abstraction function here // // // The rep invariant is: // b) Write the rep invariant here /// //the rep private ArrayList items; // constructor public QueueOfDistinctStrings () { // EFFECTS: Creates a new QueueOfDistinctStrings object items = new ArrayList(); } // MODIFIES: this // EFFECTS: Appends the element at the end of the queue if the element is not in the queue, otherwise // does nothing. public void enqueue (String element) throws Exception { if(element == null) throw new Exception(); if(false == items. contains (element)) items.add (element); } public String dequeue () throws Exception { // MODIFIES: this // EFFECTS: Removes an element from the front of the queue if (items.size() == 0) throw new Exception(); return items.remove(0); } public boolean repok () { // EFFECTS: Returns true if the rep invariant holds for this // object; otherwise returns false // c) Write the code for the repoK() here public String toString() { // EFFECTS: Returns a string that contains the strings in the queue, the front element and the end element. // Implements the abstraction function. 11 d) Write the code for the toString() here }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!