/* ***************************************************************************** * Name: * NetID: * Precept: * * Description: Object-oriented implementation of a 2-D of a 2D vball. * **************************************************************************** */ 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(); StdOut.println(b1.toString()); StdOut.println(b1); // call to toString() implied! // initialize standard drawing StdDraw.setXscale(-1.0, +1.0); StdDraw.setYscale(-1.0, +1.0); StdDraw.enableDoubleBuffering(); // main animation loop while (true) { StdDraw.clear(StdDraw.GRAY); StdDraw.setPenColor(StdDraw.BLACK); b1.move(); b2.move(); b1.draw(); b2.draw(); StdDraw.show(); StdDraw.pause(20); } } }