Program 04
Program 04
A class called MyPoint, which models a 2D point with x and y coordinates, is designed as follows:
A default (or “no-arg”) constructor that construct a point at the default location of (0, 0).
A overloaded constructor that constructs a point with the given x and y coordinates.
A toString() method that returns a string description of the instance in the format “(x, y)”.
A method called distance(int x, int y) that returns the distance from this point to another
point at the given (x, y) coordinates
An overloaded distance(MyPoint another) that returns the distance from this point to the
given MyPoint instance (called another)
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.
*/
Mypoint() {
this.x = 0;
this.y = 0;
}
Mypoint(int x, int y) {
this.x = x;
this.y = y;
}
int[] getXY() {
int[] coordinates = {x, y};
return coordinates;
}
double Distance() {
return Distance(0, 0);
}
}