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
There are some issues with the legislation. It is giving some idea issues imputable to which its proofing couldnt be done