public class MovingBall { double x, y ; double velX, velY ; double rad ; public MovingBall() { x = y = 0.5 ; velX = velY = 0.02 ; rad = 0.02 ; } public MovingBall(double inx, double iny, double inrad, double inVelX, double inVelY) { x = inx ; y = iny ; velX = inVelX ; velY = inVelY ; rad = inrad ; } public double getRad() { return rad;} public void UpdateLocation() { // if new x outside boundary, negate velX if ( ( (x + velX +rad) > 1.0) || ((x+velX-rad) < 0) ) velX *= -1 ; if ( ((y + velY + rad) > 1.0) || ((y+velY -rad) < 0)) velY *= -1 ; x += velX ; y += velY ; } public void Draw() { StdDraw.setPenColor(StdDraw.BLACK) ; StdDraw.filledCircle(x,y,rad) ; } }