/************************************************************* * Name: * NetID: * Precept: * * Description: Object-oriented implementation of a 2-D * bouncing ball. *************************************************************/ public class Ball { // declare instance variables _____________________________________________ // position _____________________________________________ // velocity _____________________________________________ // radius // other instance variables? up to you // constructor public Ball() { // always start ball position at (0, 0) // initial velocity and size generated randomly } // draw the ball, but not the background public void draw() { } // bounce off vertical wall by reflecting x-velocity private void bounceOffVerticalWall() { } // bounce off horizontal wall by reflecting y-velocity private void bounceOffHorizontalWall() { } // move the ball one step, but don't draw it public void move() { // bounce off wall(s) if you are near the border // update position using unit change in time } // test client to create and animate just 2 balls. // this part is already complete. public static void main(String[] args) { // create and initialize two balls Ball b1 = new Ball(); Ball b2 = new Ball(); // animate them StdDraw.setXscale(-1.0, +1.0); StdDraw.setYscale(-1.0, +1.0); while (true) { StdDraw.setPenColor(StdDraw.GRAY); StdDraw.filledSquare(0.0, 0.0, 1.0); StdDraw.setPenColor(StdDraw.BLACK); b1.move(); b2.move(); b1.draw(); b2.draw(); StdDraw.show(20); } } }