/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author roxana */ public class Driver { /** * @param args the command line arguments */ public static void main(String[] args) { ArrayBag aBag1 =new ArrayBag(); testIsFull(aBag1, false); String[] contentsOfBag1 ={"A","A","B","A","C","A"}; testAdd(aBag1, contentsOfBag1); testIsFull(aBag1, false); ArrayBag aBag2 =new ArrayBag(7); System.out.println("\nA new empty bag:"); testIsFull(aBag2, false); String[] contentsOfBag2 ={"A","B","A","C","B","C","D"}; testAdd(aBag2,contentsOfBag2); testIsFull(aBag2, true); /* * WEEK 3 */ aBag1.replace("A", "Z"); System.out.println("Replaced one element in the bag: "); displayBag(aBag1); aBag1.removeAll("C");; System.out.println("Removed all *C* from the bag: "); displayBag(aBag1); System.out.println("Bag1 contains the same elements as Bag2: "+aBag1.equals(aBag2)); } private static void testIsFull(BagInterface aBag, boolean correctResult) { 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"); } private static void testAdd(BagInterface aBag, String[] content) { System.out.println("Adding to the bag: "); for (int index =0; index aBag) { System.out.println("The bag contains the following string(s):"); Object[] bagArray =aBag.toArray(); for (int index=0; index