#### Class Circle and Method coderinme

Design a class Circle and implement the following methods:

Define a circle method to compute its area

Define a circle method to compute its perimeter

Define a method that takes a given point represented by a pair of numbers and checks whether or not the point is inside the circle.

The circle class needs to have instance variables to store the radius of the circle, and the x and y coordinates of the center. Add main program to test the class Circle repeatedly, until user enters negative value for the radius of the circle.

Program:

```
import java.io.*;
class Circle
{
private double radius;
private double x;
private double y;
public Circle(double X,double Y,double rd)
{
x=X;
y=Y;
radius=rd;
}
public double Area()
{
return (Math.PI*radius*radius);
}
public double Perimeter()
{
return (Math.PI*2*radius) ;
}
public void checkPoint(double a,double b )
{
double d=Math.sqrt((x-a)*(x-a)+(y-b)*(y-b));
if(radius<d)
System.out.println("The given point is outside the circle");
else
System.out.println("The given point is inside the circle");
}
}
public class Q21
{
public static void main(String[] args) throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in)) ;
while(true)
{
System.out.print("Enter the radius of the circle to proceed or enter a negative value of radius to stop:");
double r=Double.parseDouble(in.readLine());
if (r<=0)
break;
System.out.print("Enter the co-ordinates of the centre of the circle: ");
double c1=Double.parseDouble(in.readLine());
double c2=Double.parseDouble(in.readLine());
Circle C=new Circle(c1,c2,r);
System.out.print("Area of the circle is : "+C.Area());
System.out.println("\nPerimeter of the circle is : "+C.Perimeter());
System.out.print("Enter the co-ordinates of the point: ");
double p1=Double.parseDouble(in.readLine());
double p2=Double.parseDouble(in.readLine());
C.checkPoint(p1,p2);
}
}
}
```

For more programs on Java, visit our Java Archives

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme