Java Reference
In-Depth Information
System.out.print("\nTesting the method isFull with ");
if (correctResult)
System.out.println("a full bag:");
else
System.out.println("a bag that is not full:");
System.out.print("isFull finds the bag ");
if (correctResult && aBag.isFull())
System.out.println("full: OK.");
else if (correctResult)
System.out.println("not full, but it is full: ERROR.");
else if (!correctResult && aBag.isFull())
System.out.println("full, but it is not full: ERROR.");
else
System.out.println("not full: OK.");
} // end testIsFull
// Tests the method toArray while displaying the bag.
private static void displayBag(BagInterface<String> aBag)
{
System.out.println("The bag contains the following string(s):");
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 ArrayBagDemo1
Output
Testing the method isFull with a bag that is not full:
isFull finds the bag not full: OK.
Adding to the bag: A A B A C A
The bag contains the following string(s):
A A B A C A
Testing the method isFull with a bag that is not full:
isFull finds the bag not full: OK.
A new empty bag:
Testing the method isFull with a bag that is not full:
isFull finds the bag not full: OK.
Adding to the bag: A B A C B C D
Search WWH ::




Custom Search