File: /home/mybfan1011/MyPoint.
java Page 1 of 2
import [Link];
public class MyPoint{
private int x;
private int y;
public MyPoint(){
this.x=0;
this.y=0;
}
public MyPoint(int x,int y){
this.x=x;
this.y=y;
}
public void setXY(int x, int y){
this.x=x;
this.y=y;
}
public int[] getXY(){
return new int[]{x,y};
}
public String toString(){
return"("+x+","+y+")";
}
public double distance(int x, int y){
int xDiff=this.x-x;
int yDiff=this.y-y;
return [Link](xDiff*xDiff+yDiff*yDiff);
}
public double distance(MyPoint another){
int xDiff=this.x-another.x;
int yDiff=this.y-another.y;
return [Link](xDiff*xDiff+yDiff*yDiff);
}
public double distance(){
return distance(0,0);
}
public static void main(String[]args){
MyPoint point1=new MyPoint(1,2);
MyPoint point2=new MyPoint(4,6);
[Link]("Point 1:"+ [Link]());
[Link]("Point 2:"+ [Link]());
[Link]("Distance between Point 1 and (4,6):"+[Link](4,6));
[Link]("Distance between Point 1 and Point
2:"+[Link](point2));
[Link]("Distance between Point 1 and the origin:"+[Link]());
}
}
/** output:-
Point 1:(1,2)
Point 2:(4,6)
Distance between Point 1 and (4,6):5.0
Distance between Point 1 and Point 2:5.0
File: /home/mybfan1011/[Link] Page 2 of 2
Distance between Point 1 and the origin:2.23606797749979 **/