Problem

Define a class of bags that implements the interface BagInterface, as given in Listing of...

Define a class of bags that implements the interface BagInterface, as given in Listing of Chapter 1, and is a subclass of LinkedChainBase, as given in Listing

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 The abstract base class LinkedChainBase

public abstract class LinkedChainBase{  private Node firstNode; // reference to first node  private int numberOfEntries  public LinkedChainBase()  {  clear();  } // end default constructor   . . .   . . .  protected class Node  {  private T data; // data portion  private Node next; // next to next node  protected Node(T dataPortion)  {  data = dataPortion;  next = null;  } // end constructor  private Node(T dataPortion, Node nextNode)  {  data = dataPortion;  next = nextNode;  } // end constructor   . . .   . . .  } // end Node} // end LinkedChainBase

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