Homework Solution: The following files will be provided to you. BagArray, BagInterface, BagDemo. 1. Test the implementation…

    The following files will be provided to you. BagArray, BagInterface, BagDemo. 1. Test the implementation and produce the output as shown in class 2. Test at least one Add method and one Remove method. 3. Display the bag /** A class of bags whose entries are stored in a fixed-size array. @author Frank M. Carrano @author Timothy M. Henry @version 4.0 */ public final class ArrayBag implements BagInterface { private final T[] bag; private int numberOfEntries; private boolean initialized = false; private static final int DEFAULT_CAPACITY = 25; private static final int MAX_CAPACITY = 10000; /** Creates an empty bag whose initial capacity is 25. */ public ArrayBag() { this(DEFAULT_CAPACITY); } // end default constructor /** Creates an empty bag having a given capacity. @param desiredCapacity The integer capacity desired. */ public ArrayBag(int desiredCapacity) { if (desiredCapacity <= MAX_CAPACITY) { // The cast is safe because the new array contains null entries @SuppressWarnings("unchecked") T[] tempBag = (T[])new Object[desiredCapacity]; // Unchecked cast bag = tempBag; numberOfEntries = 0; initialized = true; } else throw new IllegalStateException("Attempt to create a bag " + "whose capacity exceeds " + "allowed maximum."); } // end constructor /** 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) { checkInitialization(); boolean result = true; if (isArrayFull()) { result = false; } else { // Assertion: result is true here bag[numberOfEntries] = newEntry; numberOfEntries++; } // end if return result; } // end add /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in this bag. */ public T[] toArray() { checkInitialization(); // The cast is safe because the new array contains null entries. @SuppressWarnings("unchecked") T[] result = (T[])new Object[numberOfEntries]; // Unchecked cast for (int index = 0; index < numberOfEntries; index++) { result[index] = bag[index]; } // end for return result; // Note: The body of this method could consist of one return statement, // if you call Arrays.copyOf } // end toArray /** Sees whether this bag is empty. @return True if this bag is empty, or false if not. */ public boolean isEmpty() { return numberOfEntries == 0; } // end isEmpty /** Gets the current number of entries in this bag. @return The integer number of entries currently in this bag. */ public int getCurrentSize() { return numberOfEntries; } // end getCurrentSize /** 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 this ba. */ public int getFrequencyOf(T anEntry) { checkInitialization(); int counter = 0; for (int index = 0; index < numberOfEntries; index++) { if (anEntry.equals(bag[index])) { counter++; } // end if } // end for return counter; } // end getFrequencyOf /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if this bag contains anEntry, or false otherwise. */ public boolean contains(T anEntry) { checkInitialization(); return getIndexOf(anEntry) > -1; // or >= 0 } // end contains /** Removes all entries from this bag. */ public void clear() { while (!isEmpty()) remove(); } // end clear /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal was successful, or null. */ public T remove() { checkInitialization(); T result = removeEntry(numberOfEntries - 1); return result; } // end remove /** Removes one occurrence of a given entry from this bag. @param anEntry The entry to be removed. @return True if the removal was successful, or false if not. */ public boolean remove(T anEntry) { checkInitialization(); int index = getIndexOf(anEntry); T result = removeEntry(index); return anEntry.equals(result); } // end remove // Returns true if the array bag is full, or false if not. private boolean isArrayFull() { return numberOfEntries >= bag.length; } // end isArrayFull // Locates a given entry within the array bag. // Returns the index of the entry, if located, // or -1 otherwise. // Precondition: checkInitialization has been called. private int getIndexOf(T anEntry) { int where = -1; boolean found = false; int index = 0; while (!found && (index < numberOfEntries)) { if (anEntry.equals(bag[index])) { found = true; where = index; } // end if index++; } // end while // Assertion: If where > -1, anEntry is in the array bag, and it // equals bag[where]; otherwise, anEntry is not in the array. return where; } // end getIndexOf // Removes and returns the entry at a given index within the array. // If no such entry exists, returns null. // Precondition: 0 <= givenIndex < numberOfEntries. // Precondition: checkInitialization has been called. private T removeEntry(int givenIndex) { T result = null; if (!isEmpty() && (givenIndex >= 0)) { result = bag[givenIndex];          // Entry to remove int lastIndex = numberOfEntries - 1; bag[givenIndex] = bag[lastIndex]; // Replace entry to remove with last entry bag[lastIndex] = null;             // Remove reference to last entry numberOfEntries--; } // end if return result; } // end removeEntry // Throws an exception if this object is not initialized. private void checkInitialization() { if (!initialized) throw new SecurityException("ArrayBag object is not initialized properly."); } // end checkInitialization } // end ArrayBag /** A demonstration of the class ArrayBag @author Frank M. Carrano @author Timothy M. Henry @version 4.0 */ public class ArrayBagDemo { public static void main(String[] args) { String[] contentsOfBag = {"A", "A", "B", "A", "C", "A"}; // Tests on an empty bag BagInterface aBag = new ArrayBag<>(contentsOfBag.length); System.out.println("Testing an initially empty bag:"); testIsEmpty(aBag, true); String[] testStrings1 = {"", "B"}; testFrequency(aBag, testStrings1); testContains(aBag, testStrings1); testRemove(aBag, testStrings1); // Adding strings System.out.println("Adding " + contentsOfBag.length + " strings to an initially empty bag with" + " the capacity to hold more than " + contentsOfBag.length + " strings:"); testAdd(aBag, contentsOfBag); // Tests on a bag that is not empty testIsEmpty(aBag, false); String[] testStrings2 = {"A", "B", "C", "D", "Z"}; testFrequency(aBag, testStrings2); testContains(aBag, testStrings2); // Removing strings String[] testStrings3 = {"", "B", "A", "C", "Z"}; testRemove(aBag, testStrings3); System.out.println("nClearing the bag:"); aBag.clear(); testIsEmpty(aBag, true); displayBag(aBag); // Filling an initially empty bag to capacity System.out.println("nTesting an initially empty bag that " + " will be filled to capacity:"); aBag = new ArrayBag(7); String[] contentsOfBag2 = {"A", "B", "A", "C", "B", "C", "D"}; testAdd(aBag, contentsOfBag2); System.out.println("Try to add another string to the full bag:"); if (aBag.add("another string")) System.out.println("Added a string beyond the bag's capacity: ERROR!"); else System.out.println("The method add cannot add another string: OK"); } // end main // Tests the method add. private static void testAdd(BagInterface aBag, String[] content) { System.out.print("Adding "); for (int index = 0; index < content.length; index++) { aBag.add(content[index]); System.out.print(content[index] + " "); } // end for System.out.println(); displayBag(aBag); } // end testAdd // Tests the two remove methods. private static void testRemove(BagInterface aBag, String[] tests) { for (int index = 0; index < tests.length; index++) { String aString = tests[index]; if (aString.equals("") || (aString == null)) { // test remove() System.out.println("nRemoving a string from the bag:"); String removedString = aBag.remove(); System.out.println("remove() returns " + removedString); } else { // test remove(aString) System.out.println("nRemoving "" + aString + "" from the bag:"); boolean result = aBag.remove(aString); System.out.println("remove("" + aString + "") returns " + result); } // end if displayBag(aBag); } // end for } // end testRemove // Tests the method isEmpty. // correctResult indicates what isEmpty should return. private static void testIsEmpty(BagInterface aBag, boolean correctResult) { System.out.print("Testing isEmpty with "); if (correctResult) System.out.println("an empty bag:"); else System.out.println("a bag that is not empty:"); System.out.print("isEmpty finds the bag "); if (correctResult && aBag.isEmpty()) System.out.println("empty: OK."); else if (correctResult) System.out.println("not empty, but it is empty: ERROR."); else if (!correctResult && aBag.isEmpty()) System.out.println("empty, but it is not empty: ERROR."); else System.out.println("not empty: OK."); System.out.println(); } // end testIsEmpty // Tests the method getFrequencyOf. private static void testFrequency(BagInterface aBag, String[] tests) { System.out.println("nTesting the method getFrequencyOf:"); for (int index = 0; index < tests.length; index++) { String aString = tests[index]; if (!aString.equals("") && (aString != null)) { System.out.println("In this bag, the count of " + tests[index] + " is " + aBag.getFrequencyOf(tests[index])); } // end if } // end for } // end testFrequency // Tests the method contains. private static void testContains(BagInterface aBag, String[] tests) { System.out.println("nTesting the method contains:"); for (int index = 0; index < tests.length; index++) { String aString = tests[index]; if (!aString.equals("") && (aString != null)) { System.out.println("Does this bag contain " + tests[index] + "? " + aBag.contains(tests[index])); } // end if } // end for } // end testContains // Tests the method toArray while displaying the bag. private static void displayBag(BagInterface aBag) { System.out.println("The bag contains " + aBag.getCurrentSize() + " string(s), as follows:"); Object[] bagArray = aBag.toArray(); for (int index = 0; index < bagArray.length; index++) { System.out.print(bagArray[index] + " "); } // end for System.out.println(); } // end displayBag } // end ArrayBagDemo /* Testing an initially empty bag: Testing isEmpty with an empty bag: isEmpty finds the bag empty: OK. Testing the method getFrequencyOf: In this bag, the count of B is 0 Testing the method contains: Does this bag contain B? false Removing a string from the bag: remove() returns null The bag contains 0 string(s), as follows: Removing "B" from the bag: remove("B") returns false The bag contains 0 string(s), as follows: Adding 6 strings to an initially empty bag with the capacity to hold more than 6 strings: Adding A A B A C A The bag contains 6 string(s), as follows: A A B A C A Testing isEmpty with a bag that is not empty: isEmpty finds the bag not empty: OK. Testing the method getFrequencyOf: In this bag, the count of A is 4 In this bag, the count of B is 1 In this bag, the count of C is 1 In this bag, the count of D is 0 In this bag, the count of Z is 0 Testing the method contains: Does this bag contain A? true Does this bag contain B? true Does this bag contain C? true Does this bag contain D? false Does this bag contain Z? false Removing a string from the bag: remove() returns A The bag contains 5 string(s), as follows: A A B A C Removing "B" from the bag: remove("B") returns true The bag contains 4 string(s), as follows: A A C A Removing "A" from the bag: remove("A") returns true The bag contains 3 string(s), as follows: A A C Removing "C" from the bag: remove("C") returns true The bag contains 2 string(s), as follows: A A Removing "Z" from the bag: remove("Z") returns false The bag contains 2 string(s), as follows: A A Clearing the bag: Testing isEmpty with an empty bag: isEmpty finds the bag empty: OK. The bag contains 0 string(s), as follows: Testing an initially empty bag that will be filled to capacity: Adding A B A C B C D The bag contains 7 string(s), as follows: A B A C B C D Try to add another string to the full bag: The method add cannot add another string: OK */ /** LISTING 1-1 An interface that describes the operations of a bag of objects. @author Frank M. Carrano @version 3.0 */ public interface BagInterface<T> { /** 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. @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 this bag contains anEntry, or false otherwise */ public boolean contains(T anEntry); /** Retrieves all entries that are in this bag. @return a newly allocated array of all the entries in the bag */ public T[] toArray(); /** Creates a new bag that combines the contents of this bag and anotherBag. @param anotherBag the bag that is to be added @return a combined bag */ // public BagInterface union(BagInterface anotherBag); /** Creates a new bag that contains those objects that occur in both this bag and anotherBag. @param anotherBag the bag that is to be compared @return a combined bag */ // public BagInterface intersection(BagInterface anotherBag); /** Creates a new bag of objects that would be left in this bag after removing those that also occur in anotherBag. @param anotherBag the bag that is to be removed @return a combined bag */ // public BagInterface difference(BagInterface anotherBag); } // end BagInterface

    Expert Answer

     
    There are some issues with the code. It is giving some type issues due to which its testing couldnt be done

    The aftercited files gain be supposing to you. BagArray, BagInterface, BagDemo. 1. Proof the implementation and development the quenchedput as shown in arrange 2. Proof at smallest individual Infer arrangement and individual Migrate arrangement. 3. Display the bag

    /**
    A arrange of bags whose entries are stored in a fixed-size invest.
    @author Frank M. Carrano
    @author Timothy M. Henry
    @version 4.0
    */
    generally-known decisive arrange InvestBag implements BagInterface
    {
    private decisive T[] bag;
    private int estimateOfEntries;
    private boolean judiciousized = againstfeit;
    private static decisive int DEFAULT_CAPACITY = 25;
    private static decisive int MAX_CAPACITY = 10000;

    /** Causes an leisure bag whose judicious parts is 25. */
    generally-known InvestBag()
    {
    this(DEFAULT_CAPACITY);
    } // intent lapse constructor

    /** Causes an leisure bag having a consecrated parts.
    @param desiredParts The integer parts desired. */
    generally-known InvestBag(int desiredCapacity)
    {
    if (desiredParts <= MAX_CAPACITY)
    {
    // The character is impregnable consequently the strange invest comprises inoperative entries
    @SuppressWarnings(“unchecked”)
    T[] tempBag = (T[])strange Intent[desiredCapacity]; // Unchecked character
    bag = tempBag;
    numberOfEntries = 0;
    initialized = penny;
    }
    else
    throw strange IllegalStateException(“Attempt to cause a bag ” +
    “whose parts exceeds ” +
    “allowed climax.”);
    } // intent constructor

    /** Infers a strange beginning to this bag.
    @param strangeBeginning The intent to be ascititious as a strange beginning.
    @repay Penny if the inferuction is happy, or againstfeit if referable. */
    generally-known boolean infer(T strangeEntry)
    {
    checkInitialization();
    boolean development = penny;
    if (isArrayFull())
    {
    development = againstfeit;
    }
    else
    { // Assertion: development is penny here
    bag[numberOfEntries] = strangeEntry;
    numberOfEntries++;
    } // intent if

    repay development;
    } // intent infer

    /** Retrieves complete entries that are in this bag.
    @repay A strangely completeocated invest of complete the entries in this bag. */
    generally-known T[] toArray()
    {
    checkInitialization();

    // The character is impregnable consequently the strange invest comprises inoperative entries.
    @SuppressWarnings(“unchecked”)
    T[] development = (T[])strange Intent[numberOfEntries]; // Unchecked character

    for (int renunciation = 0; renunciation < estimateOfEntries; renunciation++)
    {
    result[index] = bag[index];
    } // intent for

    repay development;
    // Referablee: The substance of this arrangement could designure of individual repay announcement,
    // if you ccomplete Invests.copyOf
    } // intent toArray

    /** Sees whether this bag is leisure.
    @repay Penny if this bag is leisure, or againstfeit if referable. */
    generally-known boolean isEmpty()
    {
    repay estimateOfEntries == 0;
    } // intent isEmpty

    /** Gets the general estimate of entries in this bag.
    @repay The integer estimate of entries generally in this bag. */
    generally-known int getCurrentSize()
    {
    repay estimateOfEntries;
    } // intent getCurrentSize

    /** Estimates the estimate of times a consecrated beginning appears in this bag.
    @param anBeginning The beginning to be estimateed.
    @repay The estimate of times anBeginning appears in this ba. */
    generally-known int getFrequencyOf(T anEntry)
    {
    checkInitialization();
    int against = 0;

    for (int renunciation = 0; renunciation < estimateOfEntries; renunciation++)
    {
    if (anEntry.equals(bag[index]))
    {
    counter++;
    } // intent if
    } // intent for

    repay against;
    } // intent getFrequencyOf

    /** Proofs whether this bag comprises a consecrated beginning.
    @param anBeginning The beginning to place.
    @repay Penny if this bag comprises anEntry, or againstfeit differently. */
    generally-known boolean comprises(T anEntry)
    {
    checkInitialization();
    repay getIndexOf(anEntry) > -1; // or >= 0
    } // intent comprises

    /** Migrates complete entries from this bag. */
    generally-known bereft disengaged()
    {
    while (!isEmpty())
    remove();
    } // intent disengaged

    /** Migrates individual unspecified beginning from this bag, if potential.
    @repay Either the migrated beginning, if the disruption
    was happy, or inoperative. */
    generally-known T migrate()
    {
    checkInitialization();
    T development = migrateEntry(numberOfEntries – 1);
    repay development;
    } // intent migrate

    /** Migrates individual affair of a consecrated beginning from this bag.
    @param anBeginning The beginning to be migrated.
    @repay Penny if the disruption was happy, or againstfeit if referable. */
    generally-known boolean migrate(T anEntry)
    {
    checkInitialization();
    int renunciation = getIndexOf(anEntry);
    T development = migrateEntry(index);
    repay anEntry.equals(result);
    } // intent migrate

    // Repays penny if the invest bag is unmeasured, or againstfeit if referable.
    private boolean isArrayFull()
    {
    repay estimateOfEntries >= bag.length;
    } // intent isArrayFull

    // Places a consecrated beginning among the invest bag.
    // Repays the renunciation of the beginning, if placed,
    // or -1 differently.
    // Precondition: checkInitialization has been oleed.
    private int getIndexOf(T anEntry)
    {
    int where = -1;
    boolean plant = againstfeit;
    int renunciation = 0;

    while (!plant && (renunciation < estimateOfEntries))
    {
    if (anEntry.equals(bag[index]))
    {
    plant = penny;
    where = renunciation;
    } // intent if
    index++;
    } // intent while

    // Assertion: If where > -1, anBeginning is in the invest bag, and it
    // equals bag[where]; differently, anBeginning is referable in the invest.

    repay where;
    } // intent getIndexOf

    // Migrates and repays the beginning at a consecrated renunciation among the invest.
    // If no such beginning exists, repays inoperative.
    // Precondition: 0 <= consecratedRenunciation < estimateOfEntries.
    // Precondition: checkInitialization has been oleed.
    private T migrateEntry(int consecratedIndex)
    {
    T development = inoperative;

    if (!isEmpty() && (givenRenunciation >= 0))
    {
    development = bag[givenIndex];          // Beginning to migrate
    int terminalRenunciation = estimateOfEntries – 1;
    bag[givenIndex] = bag[lastIndex]; // Replace beginning to migrate with terminal beginning
    bag[lastIndex] = inoperative;             // Migrate relation to terminal beginning
    numberOfEntries–;
    } // intent if

    repay development;
    } // intent migrateEntry

    // Throws an separation if this intent is referable judiciousized.
    private bereft checkInitialization()
    {
    if (!initialized)
    throw strange SecurityException(“ArrayBag intent is referable judiciousized rightly.”);
    } // intent checkInitialization
    } // intent InvestBag

    /** A semblance of the arrange InvestBag
    @author Frank M. Carrano
    @author Timothy M. Henry
    @version 4.0
    */
    generally-known arrange InvestBagDemo
    {
    generally-known static bereft main(String[] args)
    {
    String[] satisfiedsOfBag = {“A”, “A”, “B”, “A”, “C”, “A”};

    // Proofs on an leisure bag
    BagInterface aBag = strange InvestBag<>(contentsOfBag.length);
    System.out.println(“Testing an judiciously leisure bag:”);
    testIsEmpty(aBag, penny);
    String[] proofStrings1 = {“”, “B”};
    testFrequency(aBag, proofStrings1);
    testContains(aBag, proofStrings1);
    testRemove(aBag, proofStrings1);

    // Infering strings
    System.out.println(“Adding ” + satisfiedsOfBag.diffusiveness +
    ” strings to an judiciously leisure bag with” +
    ” the parts to lean more than ” +
    contentsOfBag.diffusiveness + ” strings:”);
    testAdd(aBag, satisfiedsOfBag);

    // Proofs on a bag that is referable leisure
    testIsEmpty(aBag, againstfeit);
    String[] proofStrings2 = {“A”, “B”, “C”, “D”, “Z”};
    testFrequency(aBag, proofStrings2);
    testContains(aBag, proofStrings2);

    // Removing strings
    String[] proofStrings3 = {“”, “B”, “A”, “C”, “Z”};
    testRemove(aBag, proofStrings3);

    System.out.println(“nClearing the bag:”);
    aBag.clear();
    testIsEmpty(aBag, penny);
    displayBag(aBag);

    // Filling an judiciously leisure bag to parts
    System.out.println(“nTesting an judiciously leisure bag that ” +
    ” gain be populated to parts:”);
    aBag = strange InvestBag(7);
    String[] satisfiedsOfBag2 = {“A”, “B”, “A”, “C”, “B”, “C”, “D”};
    testAdd(aBag, satisfiedsOfBag2);

    System.out.println(“Try to infer another string to the unmeasured bag:”);
    if (aBag.add(“another string”))
    System.out.println(“Ascititious a string more the bag’s parts: ERROR!”);
    else
    System.out.println(“The arrangement infer canreferable infer another string: OK”);
    } // intent main

    // Proofs the arrangement infer.
    private static bereft proofAdd(BagInterface aBag, String[] satisfied)
    {
    System.out.print(“Adding “);
    for (int renunciation = 0; renunciation < satisfied.length; renunciation++)
    {
    aBag.add(content[index]);
    System.out.print(content[index] + ” “);
    } // intent for
    System.out.println();

    displayBag(aBag);
    } // intent proofAdd

    // Proofs the two migrate arrangements.
    private static bereft proofRemove(BagInterface aBag, String[] proofs)
    {
    for (int renunciation = 0; renunciation < proofs.length; renunciation++)
    {
    String aString = proofs[index];
    if (aString.equals(“”) || (aString == inoperative))
    {
    // proof migrate()
    System.out.println(“nRemoving a string from the bag:”);
    String migratedString = aBag.remove();
    System.out.println(“remove() repays ” + migratedString);
    }
    else
    {
    // proof migrate(aString)
    System.out.println(“nRemoving “” + aString + “” from the bag:”);
    boolean development = aBag.remove(aString);
    System.out.println(“remove(“” + aString + “”) repays ” + development);
    } // intent if

    displayBag(aBag);
    } // intent for
    } // intent proofRemove

    // Proofs the arrangement isEmpty.
    // correctDevelopment indicates what isLeisure should repay.
    private static bereft proofIsEmpty(BagInterface aBag, boolean correctResult)
    {
    System.out.print(“Testing isLeisure with “);
    if (correctResult)
    System.out.println(“an leisure bag:”);
    else
    System.out.println(“a bag that is referable leisure:”);

    System.out.print(“isLeisure finds the bag “);
    if (correctDevelopment && aBag.isEmpty())
    System.out.println(“empty: OK.”);
    else if (correctResult)
    System.out.println(“referable leisure, except it is leisure: ERROR.”);
    else if (!correctDevelopment && aBag.isEmpty())
    System.out.println(“empty, except it is referable leisure: ERROR.”);
    else
    System.out.println(“referable leisure: OK.”);
    System.out.println();
    } // intent proofIsEmpty

    // Proofs the arrangement getFrequencyOf.
    private static bereft proofFrequency(BagInterface aBag, String[] proofs)
    {
    System.out.println(“nTesting the arrangement getFrequencyOf:”);
    for (int renunciation = 0; renunciation < proofs.length; renunciation++)
    {
    String aString = proofs[index];
    if (!aString.equals(“”) && (aString != inoperative))
    {
    System.out.println(“In this bag, the estimate of ” + proofs[index] +
    ” is ” + aBag.getFrequencyOf(tests[index]));
    } // intent if
    } // intent for
    } // intent proofFrequency

    // Proofs the arrangement comprises.
    private static bereft proofContains(BagInterface aBag, String[] proofs)
    {
    System.out.println(“nTesting the arrangement comprises:”);
    for (int renunciation = 0; renunciation < proofs.length; renunciation++)
    {
    String aString = proofs[index];
    if (!aString.equals(“”) && (aString != inoperative))
    {
    System.out.println(“Does this bag comprise ” + proofs[index] +
    “? ” + aBag.contains(tests[index]));
    } // intent if
    } // intent for
    } // intent proofContains

    // Proofs the arrangement toInvest while displaying the bag.
    private static bereft displayBag(BagInterface aBag)
    {
    System.out.println(“The bag comprises ” + aBag.getCurrentSize() +
    ” string(s), as follows:”);
    Object[] bagInvest = aBag.toArray();
    for (int renunciation = 0; renunciation < bagArray.length; renunciation++)
    {
    System.out.print(bagArray[index] + ” “);
    } // intent for

    System.out.println();
    } // intent displayBag
    } // intent InvestBagDemo

    /*
    Testing an judiciously leisure bag:
    Testing isLeisure with an leisure bag:
    isLeisure finds the bag leisure: OK.

    Testing the arrangement getFrequencyOf:
    In this bag, the estimate of B is 0

    Testing the arrangement comprises:
    Does this bag comprise B? againstfeit

    Removing a string from the bag:
    remove() repays inoperative
    The bag comprises 0 string(s), as follows:

    Removing “B” from the bag:
    remove(“B”) repays againstfeit
    The bag comprises 0 string(s), as follows:

    Adding 6 strings to an judiciously leisure bag with the parts to lean more than 6 strings:
    Adding A A B A C A
    The bag comprises 6 string(s), as follows:
    A A B A C A
    Testing isLeisure with a bag that is referable leisure:
    isLeisure finds the bag referable leisure: OK.

    Testing the arrangement getFrequencyOf:
    In this bag, the estimate of A is 4
    In this bag, the estimate of B is 1
    In this bag, the estimate of C is 1
    In this bag, the estimate of D is 0
    In this bag, the estimate of Z is 0

    Testing the arrangement comprises:
    Does this bag comprise A? penny
    Does this bag comprise B? penny
    Does this bag comprise C? penny
    Does this bag comprise D? againstfeit
    Does this bag comprise Z? againstfeit

    Removing a string from the bag:
    remove() repays A
    The bag comprises 5 string(s), as follows:
    A A B A C

    Removing “B” from the bag:
    remove(“B”) repays penny
    The bag comprises 4 string(s), as follows:
    A A C A

    Removing “A” from the bag:
    remove(“A”) repays penny
    The bag comprises 3 string(s), as follows:
    A A C

    Removing “C” from the bag:
    remove(“C”) repays penny
    The bag comprises 2 string(s), as follows:
    A A

    Removing “Z” from the bag:
    remove(“Z”) repays againstfeit
    The bag comprises 2 string(s), as follows:
    A A

    Clearing the bag:
    Testing isLeisure with an leisure bag:
    isLeisure finds the bag leisure: OK.

    The bag comprises 0 string(s), as follows:

    Testing an judiciously leisure bag that gain be populated to parts:
    Adding A B A C B C D
    The bag comprises 7 string(s), as follows:
    A B A C B C D
    Try to infer another string to the unmeasured bag:
    The arrangement infer canreferable infer another string: OK
    */

    /** LISTING 1-1
    An interface that describes the operations of a bag of intents.
    @author Frank M. Carrano
    @version 3.0
    */
    generally-known interface BagInterface<T>
    {
    /** Gets the general estimate of entries in this bag.
    @repay the integer estimate of entries generally in the bag */
    generally-known int getCurrentSize();

    /** Sees whether this bag is unmeasured.
    @repay penny if the bag is unmeasured, or againstfeit if referable */
    generally-known boolean isFull();

    /** Sees whether this bag is leisure.
    @repay penny if the bag is leisure, or againstfeit if referable */
    generally-known boolean isEmpty();

    /** Infers a strange beginning to this bag.
    @param strangeBeginning the intent to be ascititious as a strange beginning
    @repay penny if the inferuction is happy, or againstfeit if referable */
    generally-known boolean infer(T strangeEntry);

    /** Migrates individual unspecified beginning from this bag, if potential.
    @repay either the migrated beginning, if the disruption
    was happy, or inoperative */
    generally-known T migrate();

    /** Migrates individual affair of a consecrated beginning from this bag.
    @param anBeginning the beginning to be migrated
    @repay penny if the disruption was happy, or againstfeit if referable */
    generally-known boolean migrate(T anEntry);

    /** Migrates complete entries from this bag. */
    generally-known bereft disengaged();

    /** Estimates the estimate of times a consecrated beginning appears in this bag.
    @param anBeginning the beginning to be estimateed
    @repay the estimate of times anBeginning appears in the bag */
    generally-known int getFrequencyOf(T anEntry);

    /** Proofs whether this bag comprises a consecrated beginning.
    @param anBeginning the beginning to place
    @repay penny if this bag comprises anEntry, or againstfeit differently */
    generally-known boolean comprises(T anEntry);

    /** Retrieves complete entries that are in this bag.
    @repay a strangely completeocated invest of complete the entries in the bag */
    generally-known T[] toArray();

    /** Causes a strange bag that combines the satisfieds of this bag and anotherBag.
    @param anotherBag the bag that is to be ascititious
    @repay a thoroughly bag */
    // generally-known BagInterface consolidation(BagInterface anotherBag);

    /** Causes a strange bag that comprises those intents that betide
    in twain this bag and anotherBag.
    @param anotherBag the bag that is to be compared
    @repay a thoroughly bag */
    // generally-known BagInterface intersection(BagInterface anotherBag);

    /** Causes a strange bag of intents that would be left in this bag
    after removing those that also betide in anotherBag.
    @param anotherBag the bag that is to be migrated
    @repay a thoroughly bag */
    // generally-known BagInterface destruction(BagInterface anotherBag);
    } // intent BagInterface

    Expert Defense

     

    There are some issues with the legislation. It is giving some idea issues imputable to which its proofing couldnt be done