Constructs a point with specified coordinates


Discuss the below:

Q: Design a Java class named MyPoint to represent a point with x and y coordinates. This class should contain:

- Two data fields x and y that represent the coordinates.

- A no-argument constructor that creates a point (0, 0).

- A constructor that constructs a point with specified coordinates.

- Two get methods for data fields x and y, respectively.

- A method named distance that returns the distance from this point to another point of the MyPoint type.

- A method named distance that returns the distance from this point to another point with specified x and y coordinates.

Implement the class, and also write a test program that creates two points (0, 0) and (10, 30.5) and displays the distance between them.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Constructs a point with specified coordinates
Reference No:- TGS01934737

Now Priced at $20 (50% Discount)

Recommended (95%)

Rated (4.7/5)