GEEN 163 Bouncing Circles Create a class Circle that represents a round moving d
ID: 3810134 • Letter: G
Question
GEEN 163 Bouncing Circles Create a class Circle that represents a round moving dot. A circle object needs to contain double variables to store the: Current X location of the circle's center Cument Y location of the circle's center Radius of the circle Direction of the circle's movement in radians Speed of the circle's movement The Circle class must contain a constructor Circle double x, double y, double radius) that initializes the circles center x,yand radius. The Circle class must provide the following methods: public double get Y "Returms the y coordinate of the center ofcircle. public void set Y( double vert set the y coordinate public double getX Returns the x coordinate of the center of circle. public void setX double horz set the x coordinate public double getspeed Returns the speed of the circle public void setSpeed double fast "Set the speed of the circle public double getDir Returns the direction of movement public void setDir( double compass "Set the direction of the circle in radians public double getRadius Returns the radius ofthis circle. public void move double time) Updates the x and y coordinates after the time Update the x coordinate to x cos( direction speed time Update the y coordinate to y sin( direction) speed time public boolean touches (Circle other True if the other circle touches this circle sum of the two circles radii. Your Circle class must contain the following main method: public static void main (Stringt unused) Bounce my Prog new Bounce You will need to download the Bouncejar file and tell jGRASP in Settings Classpath workspace Classpaths. Upload your completed Circle,java file to Blackboard.Explanation / Answer
PROGRAM CODE:
package shapes;
public class Circle {
double currentX;
double currentY;
double radius;
double direction;
double speed;
public Circle(double x, double y, double radius) {
currentX = x;
currentY = y;
this.radius = radius;
speed = 0;
direction = 0;
}
public double getX() {
return currentX;
}
public void setX(double currentX) {
this.currentX = currentX;
}
public double getY() {
return currentY;
}
public void setY(double currentY) {
this.currentY = currentY;
}
public double getRadius() {
return radius;
}
public double getDir() {
return direction;
}
public void setDir(double direction) {
this.direction = direction;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public void move(double time)
{
currentX += Math.cos(direction) * speed *time;
currentY += Math.sin(direction) * speed * time;
}
public boolean touches(Circle other)
{
double sumRadii = this.radius + other.getRadius();
double distanceCenters = Math.sqrt(Math.pow(other.getX()-currentX, 2) + Math.pow(other.getY()-currentY, 2));
if(distanceCenters<sumRadii)
return true;
else return false;
}
public static void main(String args[])
{
//Since Bounce call is not provided here. I'm just showcasing the implementation
Circle circle = new Circle(2, 3, 4);
circle.setSpeed(3);
circle.setDir(20);
circle.move(2);
//alternatively you can use this after importing the bounce.jar
//Bounce myprog = new Bounce();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.