Lab 7
Lab 7
Exercise (3):
A class called MyPoint, which models a 2D point with x and y
coordinates, is designed as follows:
1) Two instance variables x (int) and y (int).
2) A default (or "no-arg") constructor that construct a point at
the default location of (0, 0).
3) A overloaded constructor that constructs a point with the
given x and y coordinates.
4) A method setXY() to set both x and y.
5) A method getXY() which returns the x and y in a 2-element
int array.
6) A toString() method that returns a string description of the
instance in the format "(x, y)".
7) A method called distance(int x, int y) that returns the distance
from this point to another point at the given (x, y) coordinates
8) An overloaded distance(MyPoint another) that returns the
distance from this point to the given MyPoint instance (called
another)
9) Another overloaded distance() method that returns the
distance from this point to the origin (0,0)
Develop the code for the class MyPoint. Also develop a JAVA
program (called TestMyPoint) to test all the methods defined in
the class