第1个回答 2015-04-12
测试类:
public class MyPointTest {
public static void main(String[] args) {
MyPoint m=new MyPoint(2,3);
System.out.println(m.distance(3, 4));
}
}
MyPoint类
public class MyPoint {
private int x;
private int y;
public MyPoint(){
}
public MyPoint(int x,int y){
this.x=x;
this.y=y;
}
public void setX(int x){
this.x=x;
}
public int getx(){
return x;
}
public void setY(int y){
this.y=y;
}
public int getY(){
return y;
}
public double distance(int x,int y){
return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));
}
}