day4 test02

package day4;

class MyPoint
{
	double x;
	double y;
}

class Circle
{
final double pi=3.14;
MyPoint c; //对象的属性可以是基本数据类型,也可以是自定义的引用数据类型
double r;
//提供方法,获得半径
public void setR(MyPoint mp)
{
	r = Math.sqrt((c.x-mp.x)*(c.x-mp.x)+(c.y-mp.y)*(c.y-mp.y));
}

public double getGirth(){
	return(2*pi*r);
	}
public double getArea(){
	return(pi*r*r);
}
}

public class test02 {
	public static void main(String args[])
	{
		//创建圆对象
		Circle circle = new Circle();
		//创建两个点对象
		MyPoint mp1 = new MyPoint();
		mp1.x = 3.0;
		mp1.y = 4.0;
		MyPoint mp2 = new MyPoint();
		mp2.x = 6.0;
		mp2.y = 8.0;
		//将mp1作为圆心
		circle.c = mp1;
		//将mp2作为圆上任意一点,设置半径
		circle.setR(mp2);
		//求圆的面积和周长,打印输出
		double area = circle.getArea();
		double girth = circle.getGirth();
		System.out.println("圆的面积是:" + area);
		System.out.println("圆的周长是:" + girth);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值