/**
 * This class models the action of a bouncing ball. It is important to note
 * that this class is <i>independent</i> of the GUI. For this animation, the
 * Model does need to know the size of the box that the ball is bouncing
 * around in, and this is set from outside. Similarly, it provides a
 * makeOneStep() method so that the model can be controlled from outside the
 * class; but neither of these requires the model to know anything at all
 * about the rest of the program
 */
class Model {
  final int BALL_SIZE = 20;
  int xPosition = 0;
  int yPosition = 0;
  int xLimit, yLimit;
  int xDelta = 4;
  int yDelta = 3;
  
  /**
   * Moves the ball one step, by adding xDelta and yDelta to its xPosition
   * and yPosition, respectively, and checking for bounces off the "walls".
   */
  void makeOneStep() {
    xPosition += xDelta;
    if(xPosition < 0 || xPosition >= xLimit) {
      xDelta = -xDelta;
      xPosition += xDelta;
    }
    yPosition += yDelta;
    if(yPosition < 0 || yPosition >= yLimit) {
      yDelta = -yDelta;
      yPosition += yDelta;
     }
  }
}

