/*
 * TFChooser.java
 *
 * A simple program that helps the teaching fellows of S-111
 * decide who gets to enter the unit test grades each week.
 *
 * Author: S-111 Course Staff
 */

public class TFChooser {
     private Bag names;

     public TFChooser() {
          this.names = new ArrayBag();
     }

     public TFChooser(String[] names) {
          this();
          for (int i = 0; i < names.length; i++) {
               if (this.names.add(names[i]) == false) {
                    throw new IllegalArgumentException("bag is full!");
               }
          }
     }

     public void add(String name) {
          names.add(name);
     }

     public void excuse(String name) {
          names.remove(name);
     }

     public String choose() {
          String tf = (String) this.names.grab();
          return tf;
     }

     public String[] chooseAll() {
         ArrayBag alreadyChosen = new ArrayBag();
         String[] randNames = new String[names.numItems()];

         for (int i = 0; i < randNames.length; i++) {
             String tf = null;
             do {
                 tf = (String)names.grab();
             } while (alreadyChosen.contains(tf));

             randNames[i] = tf;
             alreadyChosen.add(tf);
         }

         return randNames;
     }
}
