Home

pool table simulation


part 1: the PoolBall class

A PoolBall is a sphere that rolls on a PoolTable. The ball has a current position(xPos,yPos) in centimeters and a current velocity(xVel,yVel) in centimeters per second. A PoolBall knows how to update its position by using a duration (in seconds) multiplied by the velocity (in centimeters per second). A PoolBall also has setters and getters for position and velocity; the PoolBall keeps its data private and only exposes the data through the setters and getters.

The x and y dimensions are independent of each other and handled identically.

Write the class PoolBall using this outline.



public class PoolBall {
	// class variables 






	// constructor
	public PoolBall( double xPosition, double yPosition, double xVelocity, double yVelocity ) {
		






	}

	// simulate motion
	public void update( double seconds ) {
	



	}

	// getters

	public double getXPos() {                                               }

	public double getYPos() {                                               }
	
	public double getXVel() {                                               }

	public double getYVel() {                                               }
	
	// setters

	public void setXPos( double xPos ) {                                    }

	public void setYPos( double yPos ) {                                    }

	public void setXVel( double xVel ) {                                    }

	public void setYVel( double yVel ) {                                    }
}






Part 2: the pool table class

Write the PoolTable class (separate page, not supplied) from this specification:

A PoolTable is a rectangle of xsize=234 centimeters by ysize=117 centimeters and has an array of 16 PoolBalls from part 1.

The PoolTable constructor should use a loop to create the 16 balls at random positions within the rectangle. All xVelocities and yVelocities should be 0.0.

PoolBalls are 5.72 centimeters in diameter.

The distance between two PoolBalls is sqrt( ( difference of x positions)^2 + (difference of y positions)^2)

write a method named isTouching( PoolBall A, PoolBall B) that reports true if two balls are less than or equal to a diameter apart.

Write a method named anyTouching() that reports true if any PoolBall isTouching any other PoolBall.

Write a method atEdge(PoolBall C) that reports true if C has a position that is off the table in any direction.

Extra Credit: what comes next? What should it be named?