// a box has its dimensions and a bunch of balls in it 
class box {
     
   // attributes
   float x, y; // top left coords of a box
   float w, h; // width & height of the box
   ballInBox[] balls; // Every box contains a number of balls
   int nBalls;
   
   // contructor(s)
   
   box() {
   this(random(width), random(height), 50, 50, 10);
   } // box()
   
   box(float _x, float _y, float _w, float _h, int n) {
   x = _x;
   y = _y;
   w = _w;
   h = _h;
   nBalls = n;
   
   // create n balls
   balls = new ballInBox[nBalls];
   
   // initialize ball objects
   for (int i=0; i < nBalls; i++) {
   balls[i] = new ballInBox(random(w), random(height/4, h),
   2, color(0), this);
   }
   } // box()
   
   // behavior(s)
   void display() {
   pushMatrix();
   // draw the box
   translate(x, y);
   stroke(0);
   fill(255);
   rect(0, 0, w, h);
   // draw the balls in it
   for (int i=0; i < balls.length; i++) {
   balls[i].display();
   }
   popMatrix();
   } // display()
   
   void update() {
   // move every ball as it is supposed to move
   for (int i=0; i < balls.length; i++) {
   balls[i].move();
   }
   } // update()
   } // class