Java、MyPoint类

在这里插入图片描述


—————————————————————
                MyPoint
—————————————————————
-x: double
-y: double
—————————————————————
+MyPoint()
+MyPoint(x: double, y: double)
+distance(point: MyPoint): double
+distance(x: double, y: double): double
+getX(): double
+getY(): double
—————————————————————


package pack2;

public class MyPoint {
	private double x, y;	//x、y坐标
	
	/**带(0,0)的无参构造方法*/
	public MyPoint() {
		this(0, 0);
	}

	/**带(x,y)的构造方法*/
	public MyPoint(double x, double y) {
		this.x = x;
		this.y = y;
	}

	/**返回该点到指定对象点的距离*/
	public double distance(MyPoint point) {
		return Math.sqrt(Math.pow(x - point.getX(), 2) + Math.pow(y - point.getY(), 2));
	}
	
	/**返回该点到指定坐标的距离*/
	public double distance(double x, double y) {
		return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2));
	}
	
	/**返回x坐标*/
	public double getX() {
		return x;
	}

	/**返回y坐标*/
	public double getY() {
		return y;
	}

//——————————————————————————————————————————————————
	public static void main(String[] args) {
 		System.out.println("The distance is " + new MyPoint().distance(new MyPoint(10, 
                 30.5)));
	}

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值