package CircleTest;
import java.util.Scanner;
import java.math.BigDecimal;
import java.text.DecimalFormat;
class Point{
private int x;
private int y;
public Point() {
x = 0;
y = 0;
}
public Point(int x) {
this.x = x;
this.y = x;
}
public Point(int x,int y){
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String toString() {
return "("+x+","+y+")";
}
}
class Circle{
private int x;
private int y;
private Point o = new Point(x,y);
private double r;
private static final double pi=3.1415926535;
public Circle(Point o,double r) {
this.o = o;
this.r = r;
this.x = o.getX();
this.y = o.getY();
}
public Point getO() {
return o;
}
public double getR() {
return r;
}
public double getArea(){
return pi*r*r;
}
public boolean compare(double d1,double d2) {
BigDecimal val1=new BigDecimal(d1);
BigDecimal val2=new BigDecimal(d2);
if(val1.compareTo(val2) < 0||val1.compareTo(val2) == 0) {
return true;}
else {
return false;}
}
public boolean contains(Point p) {
double x = Math.abs(p.getX() - this.x);
double y = Math.abs(p.getY() - this.y);
double d1 = x*x+y*y;
double d2 = r*r;
return compare(d1,d2);
}
public boolean contains(int x,int y) {
double dx = Math.abs(x - this.x);
double dy = Math.abs(y - this.y);
double d1 = dx*dx+dy*dy;
double d2 = r*r;
return compare(d1,d2);
}
public String toString() {
return "("+"("+x+","+y+")"+","+r+")";
}
}
public class CircleTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner san = new Scanner(System.in);
int x = san.nextInt();
int y = san.nextInt();
double r = san.nextDouble();
int t = san.nextInt();
Circle circle= new Circle(new Point(x,y),r);
Point p = new Point(t);
System.out.println(String.format("Area of Circle"+circle.toString()+" is:"+"%.2f",circle.getArea()));
if(circle.contains(p)) {
System.out.println("Point"+p.toString()+" is in the Circle"+circle.toString());
}
else {
System.out.println("Point"+p.toString()+" is not in the Circle"+circle.toString());
}
}}
何欣颜
- 粉丝: 43
- 资源: 4741