import java.util.ArrayList;

/**
 * Class representing a bin
 * @author Robert Cohen, originally
 */

public class Bin {
  private int id;
  private ArrayList<Box> boxes = new ArrayList<Box>();
  private int used;

  /**
   * The capacity of a bin.
   */
  public static final int CAPACITY = 10;

  /**
   * Constructs a bin with the given id.
   * @param id int
   */
  public Bin(int id) {
    this.id = id;
  }

  /**
   * Adds a box to the bin.
   * @param b the Box to add
   * @return status: 0 = OK, -1 = too-big
   */
  public boolean addBox(Box b) {
    if (b.height() > availableSpace()) {
      return false;
    }
    used += b.height();
    boxes.add(b);
    return true;
  }

  /**
   * Returns the available space in the bin.
   * @return the available space in the bin
   */
  public int availableSpace() {
    return CAPACITY - used;
  }

  /**
   * Overrides the default method.
   * @return A string representation of the Bin (all on one line)
   */
  public String toString() {
    return "Bin " + id + ":\t" + boxes;
  }
}
