Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the class \'Point\' which has two member variables x, and y. Create a new

ID: 3747119 • Letter: G

Question

Given the class 'Point' which has two member variables x, and y. Create a new method in the class called "Distance" that returns the Euclidean distance of the point object from the origin (0,0). Choose right method:

1. public double Distance()

{

return Math.sqrt(x*x + y*y);

}

2. public double Distance()

{

return (x*x + y*y);

}

3. public double Distance()

{

return Math.sqrt(x + y);

}

4. public double Distance()

{

return x;

}

1. public double Distance()

{

return Math.sqrt(x*x + y*y);

}

2. public double Distance()

{

return (x*x + y*y);

}

3. public double Distance()

{

return Math.sqrt(x + y);

}

4. public double Distance()

{

return x;

}

public class Point f private int x; private int y; public void setX(int x) this.x -x; public void setY(int y) this.yey; public void setXY(int x, int y,) x-y; public boolean IsEqual (Point p) public void DisplayPoint() System.out.println("("+x "," + y ")"); public void movePoint(int deltax, int deltay) (// 'x' is increased by deltax and y is increased by deltay public void SetLocation (Point P) (//make point to have the specified location P. public static void main(String[] args) t /I TODO Auto-generated method stub Point P1 new Point(); Point P2 -new Point(); P1.setx(5); P1.setY (6); P2.setx(5); P2.setY (6); System.out.println(P1.IsEqual(P2)); P2.setXY(3,4); System.out.println(P1.IsEqual(P2));

Explanation / Answer

option1.

public double Distance()

{

return Math.sqrt(x*x + y*y);

}   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote