package com.basic;
import com.basic.InnerClass.Inner;
/**
* 圆类,以圆心和半径来区分两个圆是否相同。
*
* @author Administrator
*/
public class Circle
{
private static final int CONSTANT_TWO = 2;
/**
* 圆心
*/
private String centerPoint;
/**
* 半径
*/
private double radius;
/**
* 无参构造器
*/
public Circle()
{
}
/**
* 有参构造器
*
* @param centerPoint
* 圆心(可以继续封装成坐标)
* @param radius
* 半径
*/
public Circle( String centerPoint,double radius )
{
super();
this.centerPoint = centerPoint;
this.radius = radius;
}
/**
* 获取圆心值
*
* @return 圆心值
*/
private String getCenterPoint()
{
return centerPoint;
}
/**
* 设置圆心值
*
* @param centerPoint
*/
private void setCenterPoint( String centerPoint )
{
this.centerPoint = centerPoint;
}
/**
* 获取圆半径
*
* @return
*/
private double getRadius()
{
return radius;
}
/**
* 设置圆半径
*
* @param radius
*/
private void setRadius( long radius )
{
this.radius = radius;
}
/**
* 计算圆周长
*
* @return
*/
public double caculatePerimeter()
{
return Math.PI * this.radius * CONSTANT_TWO;
}
/**
* 计算圆面积
*
* @return
*/
public double caculateArea()
{
return Math.PI * this.radius * this.radius;
}
/**
* 重写圆类的toString方法
*/
@Override
public String toString()
{
return "Circle [centerPoint=" + centerPoint + ", radius=" + radius
+ "]";
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result
+ ((centerPoint == null) ? 0 : centerPoint.hashCode());
long temp;
temp = Double.doubleToLongBits( radius );
result = prime * result + (int)(temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
return true;
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
Circle other = (Circle)obj;
if ( centerPoint == null )
{
if ( other.centerPoint != null )
return false;
} else if ( !centerPoint.equals( other.centerPoint ) )
return false;
if ( Double.doubleToLongBits( radius ) != Double
.doubleToLongBits( other.radius ) )
return false;
return true;
}
public static void main( String[] args )
{
Circle circle = new Circle( "a1", 10 );
System.out.println( circle );
double perimeter = circle.caculatePerimeter();
System.out.println( circle + "的周长为:" + perimeter );
double area = circle.caculateArea();
System.out.println( circle + "的面积为:" + area );
}
}