设计Point类用来定义平面上的一个点,用构造方法传 递坐标位置,方法有计算两点的距离。编写测试类,在该类中实现Point类的对象。

package practise001;

/**
 ************************************
 * @author Hejing
 * @date   2017年12月13日
 * @class  Point.java
 * 
 ************************************
 *///设计Point类用来定义平面上的一个点,用构造方法传
//递坐标位置,方法有计算两点的距离。编写测试类,在该类中实现Point类的对象。
public class Point {
	 double  x1 ;
	 double  x2 ;
	 double  y1 ;
	 double  y2 ;
	double dis;
	public  Point(double a,double b,double c,double d) {
		this.x1 =a;
		this.y1 =b;
		this.x2 =c;	
		this.y2 =d;	
	}
	void distance() {
		dis=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		System.out.println("第一个点坐标为"+x1+"  "+y1);
		System.out.println("第一个点坐标为"+x2+"  "+y2);
		System.out.println("x y两点之间距离为"+dis);
	}

}



package practise001;

/**
 ************************************
 * @author Hejing
 * @date   2017年12月13日
 * @class  Test.java
 * 
 ************************************
 */
public class Test {
public static void main(String[] args) {
	Point p=new Point(0,3.0,0,4.0);
	p.distance();
}
}

猜你喜欢

转载自blog.csdn.net/qq_37843372/article/details/79332148