Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a java program.create a class circle that represents a round moving dot.

ID: 3759562 • Letter: C

Question

create a java program.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 circles center,current Y location of the circles center,radius of the circl,direction of the circles movement in radians,speed of the circles movement. The circle class must contain a constructor circle(double x,double y, double radians) that initializes the circles center x,y,radius. The circle class must provide the following methods: public double geyY()/*returns the y coordinate of the center of this circle*/ public double getX()/*returns the x coordinate of the center of this circle*/ public double getRadius()/*returns the radius of this circle*/ public double getDir()/*returns the direction of movement*/ public void setX(double horz)/*set the x coordinate*/ public void setY(double vert)/*set the y coordinate*/ public void setSpeed(double fast)/*set the speed of the circle*/ public void getSpeed()/*get the speed of the circle*/ public void setDir(double compass)/*set the direction of the circle in radians*/ 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*/ true if the distance between the centers of the two circles, sqrt{}(x1-x2)2 +(y1 -y2 )2 is less than the sum of the two circles radii. Your circle class must contain the following main method: public static void main(String[] unused)throws InterruptedException { Bounce myProg=new Bounce(); }

Explanation / Answer

package current;


public class Circle {

   public static void main(String[] unused)throws InterruptedException {
       Circle cir1=new Circle(10,10, 5);
       Circle cir2=new Circle(10,20, 10);
       System.out.println(" C1 touches C2: "+cir1.touches(cir2));
       cir1.setDir(180);
       cir1.move(50);
       System.out.println("After moving C1 touches C2: "+cir1.touches(cir2));
   }
  
  
   //part1-A circle object needs to contain double variables to store the: current X location of the circles center,current Y location of the circles center,radius of the circl,direction of the circles movement in radians,speed of the circles movement.
  
   private double x;
   private double y;
   private double dir;
   private double speed;
   private double radius;
  
   //part2- he circle class must contain a constructor circle(double x,double y, double radians) that initializes the circles center x,y,radius.
  
   public Circle(double x,double y, double radians) {
       this.x = x;
       this.y = y;
       this.radius = radians;
   }
  
   //part-3: The circle class must provide the following methods:
  
   public double getX() {
       return x;
   }
   public double getRadius() {
       return radius;
   }

   public void setRadius(double radius) {
       this.radius = radius;
   }

   public void setX(double x) {
       this.x = x;
   }
   public double getY() {
       return y;
   }
   public void setY(double y) {
       this.y = y;
   }
   public double getDir() {
       return dir;
   }
   public void setDir(double compass) {
       this.dir = compass;
   }
   public double getSpeed() {
       return speed;
   }
   public void setSpeed(double speed) {
       this.speed = speed;
   }
  
   //part4-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 void move(double time) {
       x += Math.cos(dir)*speed*time;
       y += Math.sin(dir)*speed*time;
   }
  
   //part5-/*true if the other circle touches this circle*/ true if the distance between the centers of the two circles, sqrt{}(x1-x2)2 +(y1 -y2 )2 is less than the sum of the two circles radii.
   public boolean touches(Circle other) {
       double distance = Math.sqrt(Math.pow(this.getX() - other.getX(), 2)+Math.pow(this.getY()-other.getY(), 2));
       if(distance < (this.getRadius()+other.getRadius()))
               return true;
       return false;      
   }
}