0% found this document useful (0 votes)
16 views1 page

PGM 4

Uploaded by

sailahari118
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

PGM 4

Uploaded by

sailahari118
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package src;

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 Math.sqrt(xDiff*xDiff*+yDiff*yDiff);
}
public double distance(Mypoint another) {
return distance(another.X,another.Y);}
public double distance() {
return distance(0,0);
}
public static void main(String[]args) {

Mypoint point1 = new Program4(1,2);


Mypoint point2 = new Program4(3,4);
System.out.println("point1:"+point1.toString());
System.out.println("point2:"+point2.toString());
System.out.println("Distance between Point1 and Point2:"+point1.distance(point2));
System.out.println("Distance between Point1 to the origin:"+point1.distance());

}
}

You might also like