Respuesta :
Answer:
Following are the code to this question:
public double distance(Point next) //defining distance method that accepts Constructor
{
int x1,x2,y1,y2;//defining integer variables
double d;//defining double variable dis
x1=this.x; //use x1 variable that use this keyword to store x variable value
y1=this.y;//use y1 variable that use this keyword to store y variable value
x2=next.x;//use x2 variable that use this keyword to store x variable value
y2=next.y;//use y1 variable that use this keyword to store y variable value
d=Math.sqrt((x1-0)*(x1-0) + (y1-0)*(y1-0));//use d variable that calculates distance between p1 to origin and store its value
d=Math.sqrt((x2-0)*(x2-0) + (y2-0)*(y2-0));//use d variable that calculates distance between p2 to origin and store its value
d=Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));//calculating the distance from p1 to p2 and store its value
return d;//return dis value
}
Explanation:
In the above-given code, the double type method "distance" is defined, that accepts a constructor in its parameter, and inside the method, four integer variable "x1,x2,y1, and y2" and one double variable "d" is declared.
After holding the value of x and y into the declared integer variable the "d" variable is used, that uses the maths square method with an integer variable, which holds p1 to origin value, p2 to origin value, and the distance from p1 to p2, and use the return keyword for return its value.
