求高手用JAVA幫我設計一個完整的Point類?
你好,程序如下:
public class Point {
double x1,x2,y1,y2;
double d,x3,y3;
Point(double x1,double y1,double x2,double y2){//構造方法
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
void TestPoint(){//求距離和中點坐標
x3 = (x1 + x2)/2;
y3 = (y1 + y2)/2;
d = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
System.out.println("(" + x3 + ","+ y3 + ")");
System.out.println(d);
}
public static void main(String[] args) {
Point p = new Point(1,1,2,2);
p.TestPoint();
}
}
如果還有其他要求的話,我再改進一下。
上一篇setNumber
下一篇如何評價動畫電影白蛇