public class Particle extends Object
Particle
class represents a particle moving in the unit box,
with a given position, velocity, radius, and mass. Methods are provided
for moving the particle and for predicting and resolvling elastic
collisions with vertical walls, horizontal walls, and other particles.
This data type is mutable because the position and velocity change.
For additional documentation, see Section 6.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

Particle()
Initializes a particle with a random position and velocity.

Particle(double rx,
double ry,
double vx,
double vy,
double radius,
double mass,
Color color)
Initializes a particle with the specified position, velocity, radius, mass, and color.

Modifier and Type  Method and Description 

void 
bounceOff(Particle that)
Updates the velocities of this particle and the specified particle according
to the laws of elastic collision.

void 
bounceOffHorizontalWall()
Updates the velocity of this particle upon collision with a horizontal
wall (by reflecting the velocity in the ydirection).

void 
bounceOffVerticalWall()
Updates the velocity of this particle upon collision with a vertical
wall (by reflecting the velocity in the xdirection).

int 
count()
Returns the number of collisions involving this particle with
vertical walls, horizontal walls, or other particles.

void 
draw()
Draws this particle to standard draw.

double 
kineticEnergy()
Returns the kinetic energy of this particle.

void 
move(double dt)
Moves this particle in a straight line (based on its velocity)
for the specified amount of time.

double 
timeToHit(Particle that)
Returns the amount of time for this particle to collide with the specified
particle, assuming no interening collisions.

double 
timeToHitHorizontalWall()
Returns the amount of time for this particle to collide with a horizontal
wall, assuming no interening collisions.

double 
timeToHitVerticalWall()
Returns the amount of time for this particle to collide with a vertical
wall, assuming no interening collisions.

public Particle(double rx, double ry, double vx, double vy, double radius, double mass, Color color)
rx
 xcoordinate of positionry
 ycoordinate of positionvx
 xcoordinate of velocityvy
 ycoordinate of velocityradius
 the radiusmass
 the masscolor
 the colorpublic Particle()
public void move(double dt)
dt
 the amount of timepublic void draw()
public int count()
bounceOff(edu.princeton.cs.algs4.Particle)
,
bounceOffVerticalWall()
, and
bounceOffHorizontalWall()
.public double timeToHit(Particle that)
that
 the other particleDouble.POSITIVE_INFINITY
if the particles will not collidepublic double timeToHitVerticalWall()
Double.POSITIVE_INFINITY
if the particle will not collide
with a vertical wallpublic double timeToHitHorizontalWall()
Double.POSITIVE_INFINITY
if the particle will not collide
with a horizontal wallpublic void bounceOff(Particle that)
that
 the other particlepublic void bounceOffVerticalWall()
public void bounceOffHorizontalWall()
public double kineticEnergy()