import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

public class Ball {
    private static Random random = new Random();
    
    private int x;  // The x-coordinate of this ball's top left corner
    private int y;  // The y-coordinate of this ball's top left corner
    private int deltaX;   // The x speed of this ball: -4 to +4
    private int deltaY;   // The y speed of this ball: -4 to +4
    private int diameter; // The size of this ball: 10 to 50
    private Color color;  // The color of this ball
    
    /**
     * Creates a ball at the given x, y location with the given Color.
     * @param x the x-coordinate of this ball's top left corner.
     * @param y the y-coordinate of this ball's top left corner.
     * @param color the Color to make this ball.
     */
    public Ball(int x, int y, Color color) {
        this.x = x;
        this.y = y;
        do {
            this.deltaX = random.nextInt(9) - 5; // choose an x speed in range -4..+4
            this.deltaY = random.nextInt(9) - 5; // choose a y speed in range -4..+4
        } while (deltaX == 0 && deltaY == 0);    // don't allow both to be zero
        this.diameter = 10 + random.nextInt(41); // choose a ball size in range 10..50
        this.color = color;
    }
   
    /**
     * Returns the diameter of this ball.
     * 
     * @return the diameter.
     */
    public int getDiameter() {
        return diameter;
    }
   
    /**
     * Displays this ball on the given Graphics object.
     * 
     * @param g the Graphics object on which to draw this ball.
     */
    public void draw(Graphics g) {
        g.setColor(color);
        g.fillOval(x, y, diameter, diameter);
    }
}


