{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MovingBall

# MovingBall - An object of type MovingBall holds data about...

This preview shows pages 1–2. Sign up to view the full content.

/* An object of type MovingBall holds data about a "ball" that has a color, radius, position, speed, and direction. The ball is restricted to moving around inside a rectangle in the xy-plane. The ball can draw itself in a graphics context and will move when it is told to move. This class uses some trigonometry and vector math in its implementation. */ * import java.awt.*; i public class MovingBall { p private double xmin, xmax; // The horizontal limits on the ball's position. // The x-coordinate of the ball statisfies // xmin <= x <= xmax. private double ymin, ymax; // The vertical limits on the ball's position. // The y-coordinate of the ball statisfies // ymin <= y <= ymax. private double x,y; // Current position of the ball. private double dx,dy; // The velocity (speed + direction) of the ball. // When the travel() method is called, the // ball moves dx pixesl horizontally and dy // pixels vertically. private Color color; // The color of the ball. private double radius; // The radius of the ball. public MovingBall(double left, double right, double top, double bottom) { // Create a ball that moves within the specified limits, // left <= x <= right and top <= y <= bottom. The ball is initially // located in the middle of this range. It has a random speed // between 4 and 12 and a random direction.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

MovingBall - An object of type MovingBall holds data about...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online