Bouncing Ball

SAMPLE APPLET:

ASSIGNMENT: Your job is to take the code from the last assignment and modify it so that you get an applet which behaves like the sample. Here are the basic things you will need to do:

  1. Define a variable for the directions for x and y. Call these xDir and yDir. These will have values of 1 or -1.
  2. Define variables for the increments for x and y. Call these xInc and yInc. Their values should adjust independently.
  3. Define variables called XMAX and YMAX which are equal to d.width - 2 * RADIUS and d.height - 2 * RADIUS, repectively. You will use these to test when the ball gets to the right and bottom edges.
  4. Within the run method you will do the following for the value of x:
        x+=(xInc * xDir);  // xDir is either +1 or -1
        if(x > XMAX || x < 0){
          xDir *= -1;
          xInc++;
          xInc = xInc%5 + 2;;
          if(x > XMAX) x = XMAX -2;
          else x = 2;
        }
    
    You will treat y the same.