Problem

Repeat Project, but instead define a class of queues that implements the interface QueueIn...

Repeat Project, but instead define a class of queues that implements the interface QueueInterface, as defined in Listing in Chapter 10.

Define a class of bags that implements the interface BagInterface, as defined in Listing in Chapter 1. Use an instance of the class ArrayList to contain a bag’s entries. Then write a program that adequately demonstrates your new class. Note that you might have to handle exceptions thrown by methods of ArrayList.

LISTING A Java interface for a class of bags

/**An interface that describes the operations of a bag of objects.@author Frank M. Carrano*/public interface BagInterface{  /** Gets the current number of entries in this bag.  @return the integer number of entries currently in the bag */  public int getCurrentSize();  /** Sees whether this bag is full.  @return true if the bag is full, or false if not */  public boolean isFull();  /** Sees whether this bag is empty.  @return true if the bag is empty, or false if not */  public boolean isEmpty();  /** Adds a new entry to this bag.  @param newEntry the object to be added as a new entry  @return true if the addition is successful, or false if not */  public boolean add(T newEntry);  /** Removes one unspecified entry from this bag, if possible.  @return either the removed entry, if the removal  was successful, or null */  public T remove();  /** Removes one occurrence of a given entry from this bag,  if possible.  @param anEntry the entry to be removed  @return true if the removal was successful, or false if not */  public boolean remove(T anEntry);  /** Removes all entries from this bag. */  public void clear();  /** Counts the number of times a given entry appears in this bag.  @param anEntry the entry to be counted  @return the number of times anEntry appears in the bag */  public int getFrequencyOf(T anEntry);  /** Tests whether this bag contains a given entry.  @param anEntry the entry to locate  @return true if the bag contains anEntry, or false otherwise */  public boolean contains(T anEntry);  /** Creates an array of all entries that are in this bag.  @return a newly allocated array of all the entries in the bag */  public T[] toArray();} // end BagInterface

LISTING An interface for the ADT queue

public interface QueueInterface{  /** Adds a new entry to the back of the queue.  @param newEntry an object to be added */  public void enqueue(T newEntry);  /** Removes and returns the entry at the front of this queue.  @return either the object at the front of the queue or, if the  queue is empty before the operation, null */  public T dequeue();  /** Retrieves the entry at the front of this queue.  @return either the object at the front of the queue or, if the  queue is empty, null */  public T getFront();  /** Detects whether this queue is empty.  @return true if the queue is empty, or false otherwise */  public boolean isEmpty();  /** Removes all entries from this queue. */  public void clear();} // end QueueInterface

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT