已知有如下类的定义:public class Point { private double x,y; public Point(double a,double b) { x=a;y=b; }public double getX(){return x;}public double getY(){return y;}} 编写一个测试类 TestPoint,在此类中定义一个方法,此方法

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 21:50:26
已知有如下类的定义:public class Point { private double x,y; public Point(double a,double b) { x=a;y=b; }public double getX(){return x;}public double getY(){return y;}} 编写一个测试类 TestPoint,在此类中定义一个方法,此方法
xSj1-gZYL&~A.jJ=SuFvf0!vSH %'<ܗ$m~f^BeI؉)]n.:^{tU$h)ۏz8JIo#:酓eҮ65ǶiQ1;n3 @9E2,+_@ lv xp A˝n8^ G׭tiO a?,>$wgކ Qe>n.2]f.(şM ĕ9feuӥتhP7Wlj ѢoΎч7i :7GhBx5P< 7V98 k0 ㍽.:^̓rf/q65螘'rVtf#L_ C{U!.#o p\]OʶmtVs;Z*(X-PY9Rr:Z @%1;Q$(Ơ(3YLߥF mtYi)7eP̻[0L

已知有如下类的定义:public class Point { private double x,y; public Point(double a,double b) { x=a;y=b; }public double getX(){return x;}public double getY(){return y;}} 编写一个测试类 TestPoint,在此类中定义一个方法,此方法
已知有如下类的定义:public class Point { private double x,y; public Point(double a,double b) { x=a;
y=b;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
}
编写一个测试类 TestPoint,在此类中定义一个方法,此方法的方法头如下:
public double distance(Point p1,Point p2):此方法的求两点p1和p2的距离.
在main方法中,自己设定两个点(x1,y1)和(x2,y2),并求这两个点的距离.
急,本人感激不尽

已知有如下类的定义:public class Point { private double x,y; public Point(double a,double b) { x=a;y=b; }public double getX(){return x;}public double getY(){return y;}} 编写一个测试类 TestPoint,在此类中定义一个方法,此方法
import java.util.*;
class TestPoint
{
public double distance(Point p1,Point p2)
{
return Math.sqrt(Math.pow(p1.getX()-p2.getX(),2)+Math.pow(p1.getY()-p2.getY(),2));
}
public static void main(String[] args)
{
Point p1 = new Point(10.5,12.3);
Point p2 = new Point(-10.5,-2.0);
TestPoint t = new TestPoint();
double dis = t.distance(p1,p2);
System.out.println(dis);
}
}