The following formula gives the distance between two points (x1, y1) and (x2, y2
ID: 3634975 • Letter: T
Question
The following formula gives the distance between two points (x1, y1) and (x2, y2) in the Cartesian plane:(x2-x1)^2 + (y2-y1)^2
Given the center and a point on a circle, you can use this formula to find the radius of a circle. Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle’s radius, diameter, circumference, and area. Your program must have at least the following methods:
a. distance: This method takes as its parameters four numbers that represent two points in the plane and returns the distance between them.
b. Radius: This method takes as its parameter four numbers that represent the center and a point on the circle, calls the method distance to find the radius of the circle, and returns the circle’s radius.
c. Circumference: This method takes as its parameter a number that represents the radius of the circle and returns the circle’s circumference. (if r is the radius, the circumference is 2(Pi)r.)
d. Area: This method takes as its parameter a number that represents the radius of the circle and returns the circle’s area. (If r is the radius, the area is (Pi)r^2.)
Assume that Pi =3.1416
Explanation / Answer
Please Rate:Thanks
import java.util.*;
public class circle {
public static final double pi=3.1416;
public static void main(String[] args){
Scanner input=new Scanner(System.in);
double x1,y1,x2,y2;
double r;
System.out.println("Enter center of circle ");
x1=input.nextDouble();
y1=input.nextDouble();
System.out.println("Enter point of circle ");
x2=input.nextDouble();
y2=input.nextDouble();
r=radius(x1,y1,x2,y2);
System.out.println("Radius of circle "+r);
System.out.println("Area of circle "+area(r));
System.out.println("circumference of circle "+circumference(r));
}
public static double circumference(double radius){
return 2*pi*radius;
}
public static double area(double radius){
return pi*radius*radius;
}
public static double radius(double x1,double y1,double x2,double y2)
{
return distance(x1,y1,x2,y2);
}
public static double distance(double x1,double y1,double x2,double y2)
{
double p1=Math.pow((x2-x1),2);
double p2=Math.pow((y2-y1),2);
return p1+p2;
}
}
----------------------------------------------------------
Output:
Enter center of circle
2 2
Enter point of circle
3 6
Radius of circle 17.0
Area of circle 907.9223999999999
circumference of circle 106.81439999999999
BUILD SUCCESSFUL (total time: 12 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.