import java.util.*; public class Bin { private int id; // the id number of the bin private Vector contents; // the actual contents, as a Vector private int capacity; // the capacity of the bin private int totalWeight; // the total "weight" of the contents public Bin(int idNumber, int Capacity){ id = idNumber; contents = new Vector(); capacity = Capacity; totalWeight = 0; } // Constructor, makes a bin with an id number and a capacity public int numberOfElements(){return contents.size();} public boolean isEmpty(){return contents.isEmpty();} public boolean isFull(){return totalWeight >= capacity;} public int totalWeight(){return totalWeight;} public Vector contents(){return contents;} public int id(){return id;} public int capacity(){return capacity;} public String toString(){ return " bin[" + id + "]=" + totalWeight +" "+ contents.toString(); } public Enumeration elements(){return contents.elements();} // deliver an enumeration of the elements in the bin // This allows us to use hasMoreElements and nexElement // methods associated with the Enumeration class public void add(int n){ totalWeight = totalWeight + n; contents.addElement(new Integer(n)); } // add a number/weight n to the bin // since contents is a vector, and contains objects, // we turn the number to an Integer object. public boolean remove(int n){ if (contents.removeElement(new Integer(n))){ totalWeight = totalWeight - n; return true; } else return false; } // remove a number/weight from a bin // if the number is in the contents of the bin, remove // it and deliver true, otherwise attempt is made // to remove something that aint there, so deliver false public void clear(){ contents.removeAllElements(); totalWeight = 0; } // clear out the bin, removing all elements public boolean isLegal(){return totalWeight <= capacity;} // the bin is legal if the weight of the contents is // no greater than the capacity }