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

Exercise 2: Define a Circle class that contains: Two double data fields named xp

ID: 3747454 • Letter: E

Question

Exercise 2: Define a Circle class that contains: Two double data fields named xpos and ypos that specify the center of the circle. .A double data field radius. Three Getter methods, one each for xpos, ypos and radius. Two Setter methods: one for setting the center and one for setting the radius A constructor that creates a circle with the specified xpos, ypos and radius. method getArea(0 that returns the area of the circle A method getCircumference0 that returns the circumference of the circle. A method contains(double x, double y) that returns true if the specified point (xy) is inside this circle, false otherwise. A method touches (double x, double y) that returns true if the specified point (x.y) touches the circle. A method contains(Circle circle) that returns true if the specified circle is completely inside this circle (similar to the case of the rectangle), false otherwise. A method touches(Circle circle) that returns true if the specified circle touches this circle similar to the case of the rectangle), false otherwise. A Point is contained Point is touching

Explanation / Answer

class Circle{
  
  
double xpos,ypos, radii;
Circle(double xpos,double ypos,double radii){


this.xpos=xpos;
this.ypos=ypos;
this.radii=radii;


}




double getXpos(){

return xpos;

}
  
double getYpos(){

return ypos;

}
  
  
  
double getRadii(){

return radii;

}


void SetCentre(double x,double y){
xpos=x;
ypos=y;

}
void SetRadii(double r){
radii=r;

}

double getArea(){

return 3.14*radii*radii;
}
  
  
double getCircumference(){
  
return 2*3.14*radii;
  
}
  
  
  
boolean contains(double x,double y){
  
double d = Math.sqrt( (x-xpos)*(x-xpos) + (y-ypos)*(y-ypos) );
  
if(d<radii)
return true;
  
else
return false;
}
  
boolean touches(double x,double y){
  
double d = Math.sqrt( (x-xpos)*(x-xpos) + (y-ypos)*(y-ypos) );
  
if(d==radii)
return true;
  
else
return false;
  
}
  
boolean contains(Circle c){
  
  
double d = Math.sqrt( (this.xpos-c.xpos)*(this.xpos-c.xpos) + (this.ypos-c.ypos)*(this.ypos-c.ypos) );

if(this.radii<c.radii){
if((d+this.radii) < c.radii)
return true;
  
else
return false;
}

else{

if((d+c.radii) < this.radii)
return true;
  
else
return false;


}
  
  
}
  
  
boolean touches(Circle c){

double d1= c.radii+this.radii;
  
double d2= Math.sqrt( (this.xpos-c.xpos)*(this.xpos-c.xpos) + (this.ypos-c.ypos)*(this.ypos-c.ypos) );
  
if(d2==d1)
  
return true;
  
if(d2==Math.abs(this.radii-c.radii))
return true;
  
else
return false;
  
  
  
}
  
  
  

  
  
}